Alternate PHP Versions

From Sympl Wiki
Jump to navigation Jump to search
This article is Community Documentation and any changes may not be compatible with future updates of Sympl, and is therefore not officially supported.
The Sympl Forum may have more information.

Sympl only natively supports the Debian-bundled PHP, but with a bit of poking, it's easy to give it support for other PHP versions with PHP-FPM which doesn't break the usual Sympl stuff.

Important Information

This involves using a third-party (not official Debian) repository, which means that security fixes and other changes may take a little longer to appear in all versions.

However, the repository below is maintained by Ondřej Surý, who has been a Debian Developer since 2000, and packaged PHP for Debina since 2005, so it's considered safe in most cases.

It's also important to note that installing this will mean you have some newer packages than typical, you will not automatically receive security updates, and you may encounter issues with Debian or Sympl if not careful, so this is not fully suitable for production settings.

Setting It Up

Set this variable to the required PHP version:


You should then be fine to copy and paste these lines, one at a time...

# Get the current version running with mod_php
php_version="$( dpkg -l 'libapache2-mod-php[0-9]*' | grep '^ii' |  cut -d '-' -f '3' | awk '{ print $1 }' | sort -u )"
# List the relevant php modules so we install the same ones
php_packages="fpm $( dpkg -l "$php_version*" | grep '^ii' | cut -d '-' -f '2' | awk '{ print $1 }' )"

# Add sury repo if not already there
if [ ! -f /etc/apt/sources.list.d/php.list ] || [ ! -f /etc/apt/preferences.d/sury-php ]; then
  apt update
  apt -y install apt-transport-https lsb-release ca-certificates curl
  curl -sSLo /usr/share/keyrings/
  sh -c 'echo "deb [signed-by=/usr/share/keyrings/] $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
apt update

# Enable apache mod
a2enmod proxy_fcgi

# Attempt to install php-fpm with the relevant packages

for package in $php_packages; do
  echo ---- $package ----
  apt -y install $want_version-$package

Note that some packages such as php8.0-json are virtual packages, so may not be able to be installed normally. This will usually be okay.


Set this variable to be the domain you want to swap the PHP version on:



Swap the config to use the new PHP version:

# Create apache include dir
mkdir -p /srv/$domain/config/apache.d
echo "
    <FilesMatch \".+\.ph(ar|p|tml)$\">
        SetHandler \"proxy:unix:/run/php/$want_version-fpm.sock|fcgi://localhost\"
    <FilesMatch \".+\.phps$\">
        # Deny access to raw php sources by default
        # To re-enable it's recommended to enable access to the files
        # only in specific virtual host or directory
        Require all denied
    # Deny access to files without filename (e.g. '.php')
    <FilesMatch \"^\.ph(ar|p|ps|tml)$\">
        Require all denied
" > /srv/$domain/config/apache.d/php-fpm.conf

# Set the permisions
chown sympl:sympl /srv/$domain/config/apache.d /srv/$domain/config/apache.d/php-fpm.conf

# Make the new config live
sympl-web-configure ; service apache2 reload

At this point, a simple phpinfo() on the relevant site should report the relevant PHP version.