PHP 8 on Raspberry Pi 4
Here’s what you need to do if you want to play around with PHP 8.0.x on your Raspberry Pi 4, running the latest version of Raspberry Pi OS. I’m running Lite, but this would apply if you were running the full version as well.
Check if you already have PHP installed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
pi@rpi:~ $ dpkg -l | grep php
ii php-cgi 2:7.3+69 all server-side, HTML-embedded scripting language (CGI binary) (default)
ii php-common 2:69 all Common files for PHP packages
ii php-intl 2:7.3+69 all Internationalisation module for PHP [default]
ii php-json 2:7.3+69 all JSON module for PHP [default]
ii php-sqlite3 2:7.3+69 all SQLite3 module for PHP [default]
ii php-xml 2:7.3+69 all DOM, SimpleXML, WDDX, XML, and XSL module for PHP [default]
ii php7.3-cgi 7.3.27-1~deb10u1 armhf server-side, HTML-embedded scripting language (CGI binary)
ii php7.3-cli 7.3.27-1~deb10u1 armhf command-line interpreter for the PHP scripting language
ii php7.3-common 7.3.27-1~deb10u1 armhf documentation, examples and common module for PHP
ii php7.3-intl 7.3.27-1~deb10u1 armhf Internationalisation module for PHP
ii php7.3-json 7.3.27-1~deb10u1 armhf JSON module for PHP
ii php7.3-opcache 7.3.27-1~deb10u1 armhf Zend OpCache module for PHP
ii php7.3-readline 7.3.27-1~deb10u1 armhf readline module for PHP
ii php7.3-sqlite3 7.3.27-1~deb10u1 armhf SQLite3 module for PHP
ii php7.3-xml 7.3.27-1~deb10u1 armhf DOM, SimpleXML, WDDX, XML, and XSL module for PHP
Remove the default PHP
1
pi@rpi:~ $ sudo apt purge -y php.*
Add Sury Repository for PHP 8
There are other repositories for Ubuntu/CentOs/Fedora and even Debian, Sury is just my preference.
You can follow the instructions in this README Or
1
2
3
4
5
sudo apt-get -y install apt-transport-https lsb-release ca-certificates curl
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt-get update
Now you can install PHP 8 packages. I have pi-hole running on my Pi, and the default admin interface is exposed via php-cgi and lighttpd, so I just install the php-cgi, sqlite3 and xml packages, and apt handles all the dependencies.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
pi@rpi:~ $ sudo apt-get install php-fpm php-sqlite3 php-xml php-json php-xml php-intl
pi@rpi:~ $ dpkg -l | grep php
ii php-cgi 2:8.0+82+0~20210313.35+debian10~1.gbpa8195f all server-side, HTML-embedded scripting language (CGI binary) (default)
ii php-common 2:82+0~20210313.35+debian10~1.gbpa8195f all Common files for PHP packages
ii php-intl 2:8.0+82+0~20210313.35+debian10~1.gbpa8195f all Internationalisation module for PHP [default]
ii php-json 2:8.0+82+0~20210313.35+debian10~1.gbpa8195f all JSON module for PHP [default]
ii php-sqlite3 2:8.0+82+0~20210313.35+debian10~1.gbpa8195f all SQLite3 module for PHP [default]
ii php-xml 2:8.0+82+0~20210313.35+debian10~1.gbpa8195f all DOM, SimpleXML, WDDX, XML, and XSL module for PHP [default]
ii php8.0-cgi 8.0.5-2+0~20210503.19+debian10~1.gbp3e4ad0 armhf server-side, HTML-embedded scripting language (CGI binary)
ii php8.0-cli 8.0.5-2+0~20210503.19+debian10~1.gbp3e4ad0 armhf command-line interpreter for the PHP scripting language
ii php8.0-common 8.0.5-2+0~20210503.19+debian10~1.gbp3e4ad0 armhf documentation, examples and common module for PHP
ii php8.0-intl 8.0.5-2+0~20210503.19+debian10~1.gbp3e4ad0 armhf Internationalisation module for PHP
ii php8.0-opcache 8.0.5-2+0~20210503.19+debian10~1.gbp3e4ad0 armhf Zend OpCache module for PHP
ii php8.0-readline 8.0.5-2+0~20210503.19+debian10~1.gbp3e4ad0 armhf readline module for PHP
ii php8.0-sqlite3 8.0.5-2+0~20210503.19+debian10~1.gbp3e4ad0 armhf SQLite3 module for PHP
ii php8.0-xml 8.0.5-2+0~20210503.19+debian10~1.gbp3e4ad0 armhf DOM, SimpleXML, XML, and XSL module for PHP
pi@rpi:~ $