PHP is a programming language that commonly used to create a web applications and dynamic websites. With each release of PHP, new features and various changes are introduced.
This tutorial shows how to install PHP 8.0 on Raspberry Pi.
Connect to Raspberry Pi via SSH and execute commands to download GPG key and add repository.
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list sudo apt update
Then install PHP 8.0 with command line interface (CLI):
sudo apt install -y php8.0-common php8.0-cli
Check PHP version when installation was finished:
There are various PHP extensions that provides additional functionality. PHP extensions can be installed using the following syntax:
sudo apt install -y php8.0-extension_name
Execute the following command to install commonly used PHP extensions:
sudo apt install -y php8.0-curl php8.0-gd php8.0-mbstring php8.0-xml php8.0-zip
We can use
-m option to check what extensions are installed.
If we want completely remove any package with a name that starts with
php and anything related to it we can execute this command:
sudo apt purge -y php.*
PHP integration with MySQL or MariaDB
In order to use PHP with MySQL or MariaDB database we need to install the following extension:
sudo apt install -y php8.0-mysql
PHP integration with Apache
If we want to integrate PHP with Apache HTTP server then install the following extension:
sudo apt install -y libapache2-mod-php8.0
Once installation was completed restart Apache.
sudo service apache2 restart