PHP is an open-source general-purpose scripting language used for creating web pages and applications. It can easily integrate with multiple databases like MySQL, Oracle, PostgreSQL, Informix, Microsoft SQL Server, and Sybase. Besides integration, it supports many major protocols, such as LDAP, POP3, and IMAP.
If you are interested in installing the latest version of PHP on Raspberry Pi, follow this guide for further details.
How to Install Latest PHP Version on Raspberry Pi
To install the latest version of PHP on Raspberry Pi, follow the steps, which are mentioned below:
Step 1: Update the Repository
Before installing any new package, it is better to update the Raspberry Pi repository by using the below-written command:
If the repository isn’t updated, you can use the following command to upgrade it:
Step 2: Download the GPG key
In the Raspberry Pi system, the latest version of PHP can be installed using the third-party repository and to use this repository, you must import a GPG key using the below-mentioned command:
Step 3: Add PHP Repository
After successfully adding the GPG key, you can add the PHP repository using the following command:
Step 4: Update Repository
After adding the PHP repository, you must update the system repository through the below-given command:
In case of upgrade, you can use the following command:
Step 5: Install PHP on Raspberry Pi
After the update, you can apply the following command to install the PHP latest version on your Raspberry Pi system:
Enter “Y” when asked for permission to continue.
You can confirm the installation of PHP latest version on your system through the following command:
In the output it can be clearly seen that the latest version of PHP is installed on the system, which is 8.1.13.
Run a PHP Code
To verify if PHP is correctly installed or not, let’s run a simple code. To do it, we are adding a “Hello” message inside the PHP file through the following command.
You can replace the message ‘Hello Linux-hint’ with your own. The output will be stored in a new file named “my_file.php”:
Or open nano editor and create a PHP file by using the below-mentioned code:
Then you can type any PHP code of your choice inside this file:
Then run the file using the below-mentioned command:
The output will be displayed on the screen.
Conclusion
PHP is a server-side language used for web development. You can install the latest version of PHP on the Raspberry Pi system using a third-party repository. However, before that, you must add a GPG key to the system. Later on, you can add the repository and run the update command to update the changes. Once the repository is updated, you can successfully install the latest version of PHP on the Raspberry Pi system through the “apt” command.