Install PHP 8.0 on Raspberry Pi

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
echo "deb $(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:

php --version

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.

php -m

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

This article has 8 comments

  1. BlackSenator Reply

    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.

    • lindevs Reply

      Hi BlackSenator,
      Raspberry Pi 1 Model B has an ARMv6 compatible CPU. The repository is not supporting ARMv6. So you’ll need at least ARMv7-A compatible CPU.

    • lindevs Reply

      Hi steinmb,
      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.

      • steinmb Reply

        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 do not build for ARMv6? I mean, not even PHP 7.4.x is available.

    • lindevs Reply

      The 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 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 You need to increase the swap memory on Raspberry Pi in order to compile PHP 8.0.

  2. Gary Reply

    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?

    • lindevs Reply

      Hi, Gary
      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 Comment

Your email address will not be published. Required fields are marked *