PHP is a programming language that commonly used to create 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.2 on Raspberry Pi.
Connect to Raspberry Pi via SSH and execute command to download GPG key:
sudo wget -qO /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
Add PHP repository:
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
Update the package lists:
sudo apt update
Next, install PHP 8.2 with command line interface (CLI):
sudo apt install -y php8.2-common php8.2-cli
Check PHP version when installation was finished:
There are various PHP extensions that provide additional functionality. PHP extensions can be installed using the following syntax:
sudo apt install -y php8.2-extension_name
Execute the following command to install commonly used PHP extensions:
sudo apt install -y php8.2-curl php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip
We can use
-m option to check what extensions are installed.
PHP integration with MySQL or MariaDB
To use PHP with MySQL or MariaDB database, we need to install the following extension:
sudo apt install -y php8.2-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.2
Once installation was completed, restart Apache:
sudo service apache2 restart
Create a new
Add the following code:
<?php echo 'Hello world';
Run the following command to test a script:
If you want to completely remove PHP anything related to it, execute the following command:
sudo apt purge --autoremove -y php-common mime-support
Remove GPG key and repository:
sudo rm -rf /etc/apt/trusted.gpg.d/php.gpg
sudo rm -rf /etc/apt/sources.list.d/php.list
Remove PHP related file:
sudo rm -rf /var/lib/systemd/timers/stamp-phpsessionclean.timer
Install older versions
PHP 8.1 is an older version that is still supported. It can be installed by changing
php8.1 in this post presented commands.
The 8 Comments Found
Is there a hardware (CPU) requirement? I still had a Pi (1B) that I wanted to use for a simple script (CLI).
I have tried several times to install PHP 8 based on the current Raspbian OS lite (Buster). When I called `php -v` at the end I got` illegal instruction`. PHP 7.3 runs fine on it, with 7.4 I get the same error as with 8.0.
Raspberry Pi 1 Model B has an ARMv6 compatible CPU. The deb.sury.org repository is not supporting ARMv6. So you’ll need at least ARMv7-A compatible CPU.
Any hint of where/how to install PHP 8.0 on a ARMv6 architecture?
Right now I unable to find precompiled PHP 8.0 binaries that compatible with ARMv6 architecture. You can try to install PHP from source code. However, compilation can take a while.
Thanks for your swift reply: I did try to build but I did run out of memory. Perhaps I could try again but make sure I have a rather large swap disk enabled? Anyone know why deb.sury.org do not build for ARMv6? I mean, not even PHP 7.4.x is available.
The deb.sury.org repository contains packages for Debian. The Debian armhf port needs at least ARMv7 compatible CPU. This means that Debian armhf packages can be installed on Raspberry Pi with ARMv7 CPU. Raspberry Pi 1 and Zero has ARMv6 CPU that is incompatible with the Debian armhf port. The deb.sury.org repository don't provide packages for Debian armel (supports ARMv6 CPU). I gues that BlackSenator installed PHP 7.3 from official Raspbian repository and not from deb.sury.org. You need to increase the swap memory on Raspberry Pi in order to compile PHP 8.0.
I am doing a test install of Buster on my model3b Pi. Everything seems to be working (apache2, php8, mariadb). However, I am unable to install phpmyadmin. At the end of the install, I get ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO). All my attempts to get around this failed. I have remote tools for database management and they connect.
I'm not sure that I need phpmyadmin, but I use it on my other pi computers.
Is this a compatibility issue that can not currently be solved?
The phpMyAdmin available on official Raspbian repository is out of date and not compatible with PHP 8.0. Right now the Raspbian repository for Buster contains phpMyAdmin 4.6.6. So if you tried to install phpMyAdmin via APT package manager you got errors. You'll have to install phpMyAdmin manually. Don't forget to remove a previous version.
Leave a CommentCancel reply