Install PHP 8.3 on Raspberry Pi

Install PHP 8.3 on Raspberry Pi

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.3 on Raspberry Pi.

Install PHP

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.3 with command line interface (CLI):

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

Check PHP version when installation was finished:

php --version

There are various PHP extensions that provide additional functionality. PHP extensions can be installed using the following syntax:

sudo apt install -y php8.3-extension_name

Execute the following command to install commonly used PHP extensions:

sudo apt install -y php8.3-curl php8.3-gd php8.3-mbstring php8.3-xml php8.3-zip

We can use -m option to check what extensions are installed.

php -m

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.3-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.3

Once installation was completed, restart Apache:

sudo service apache2 restart

Testing PHP

Create a new main.php file:

nano main.php

Add the following code:

<?php

echo 'Hello world';

Run the following command to test a script:

php main.php

Uninstall PHP

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.2 is an older version that is still supported. It can be installed by changing php8.3 to php8.2 in this post presented commands.

The 10 Comments Found

  1. Avatar
    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.

    • Avatar
      lindevs Reply

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

    • Avatar
      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.

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

    • Avatar
      lindevs Reply

      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.

  2. Avatar
    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?

    • Avatar
      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.

  3. Avatar
    Philippe Reply

    Hi,
    In the past, I tried to install a more recent version of PHP on a Linux box (ppa:ondrej) and had to return back to the old one because phpMyAdmin was broken.

    After upgrade to 8.3 can you confirm that the installed version of phpMyAdmin runs always fine ? Or do I install a compatible version, and if yes have you an advice ?

    Currently, I run Raspbian GNU/Linux 11 (bullseye) with PHP 7.4 and PhpMyAdmin 5.04.

    Thanks for your feedback !

    • Avatar
      lindevs Reply

      Hi,
      As of now, the latest version of phpMyAdmin is 5.2.1. According to the release notes, it has addressed compatibility issues with PHP 8.2. Currently, phpMyAdmin may not be fully compatible with PHP 8.3.

Leave a Comment

Cancel reply

Your email address will not be published.