Open In App

How to Install PHP on Raspberry Pi?

Last Updated : 14 Feb, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

PHP is a scripting language. It is used for Web Development purposes. Along with HTML and Javascripts PHP is highly used in different aspects. We all can be used PHP in our machine just by installing it. But, while you are using it in Raspberry Pi we have to install properly Raspberry Os. It is the most important prerequisite. Without it, you can not be able to install and use it further. If you do not install Raspberry Pi Os then you can not open the terminal which was provided along with it. If you can not open the terminal you can not write the proper commands to install the PHP or any other applications.

Features:

  • PHP is very easy to use rather than other scripting languages.
  • It is faster than other scripting languages.
  • It can be installed in any operating system like macOS, Windows, Linux, etc.
  • In PHP there is no need for compilation, as it is an interpreted language.

Install PHP on Raspberry Pi

To install PHP on Raspberry Pi follow the following steps:

Step 1: Open the terminal of Raspberry Pi Os, then write the following command to connect to Raspberry Pi via SSH and then download the GPG key:

sudo wget -qO /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

Open-terminal-of-Raspberry-pi

Step 2: Now add the PHP repository using the following command: 

echo “deb https://packages.sury.org/php/ $(lsb_release -sc) main” | sudo tee /etc/apt/sources.list.d/php.list

update-the-package

Step 3: Now using the following command update the package list.

sudo apt update

Update-the-package

Wait till the process is completed.

Step 4: Then write the following command to install PHP with a command-line interface. 

sudo apt install -y php8.1-common php8.1-cli

install-PHP-with-command-line-interface

Wait till the process is completed.

Step 5: Now, your installation is successful. Write the following command to check the version of the installed PHP.

php –version

 Checking-the-version-of-PHP

Here, PHP 8 version is installed. As in my machine, it is the right version I have to install. You can also install it on your machine, PHP 8 version works well than others.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads