Upgrading to PHP8 on Webdock Focal Stacks

Last updated: November 30th 2020


In this guide we provide specific steps on how to upgrade to PHP 8 if you are on a Webdock LAMP or LEMP stack running on Ubuntu 20.04 Focal.

For older distributions, i.e. Xenial 16.04 or Bionic 18.04 you will need to upgrade your system entirely before following these steps. This procedure can then become rather involved and it is in that case probably easier to just provision a brand new Webdock server on the latest software and migrate your application files and database by hand. If you want to try the upgrade, we have guides available here.

If you want further information on how to migrate an application, we have a guide for that here. Although the guide is Wordpress-centric, the general steps are the same for most web applications.


For this procedure you need

  • To be sure you are on a Focal stack, these steps will probably not work on older Ubuntu versions
  • You have shell (SSH) access to your server set up and working - all commands in this guide assume you have executed "sudo su" and are working as root. You can also choose to pre-pend "sudo" in front of all the commands below in order to achieve the same thing.
  • You should probably take a snapshot of your server before you begin, or do this on a staging copy of your server in case something goes wrong

Optional: Remove your old php version

This step is not strictly required, but recommended. Start with removing all the old php packages for your current version of PHP. Replace 7.4 with the version of PHP you are on now:

apt remove --purge -y php7.4-cli php7.4-dev php7.4-pgsql php7.4-sqlite3 php7.4-gd php7.4-curl php-memcached php7.4-imap php7.4-mysql php7.4-mbstring php7.4-xml php-imagick php7.4-zip php7.4-bcmath php7.4-soap php7.4-intl php7.4-readline php7.4-common php7.4-pspell php7.4-tidy php7.4-xmlrpc php7.4-xsl php7.4-opcache php-apcu php7.4-fpm

Upgrade your system

Make sure all packages are up to date

apt update; apt upgrade -y

Install the new PHP 8 packages

apt install -y php8.0-cli php8.0-dev php8.0-pgsql php8.0-sqlite3 php8.0-gd php8.0-curl php-memcached php8.0-imap php8.0-mysql php8.0-mbstring php8.0-xml php-imagick php8.0-zip php8.0-bcmath php8.0-soap php8.0-intl php8.0-readline php8.0-common php8.0-pspell php8.0-tidy php8.0-xsl php8.0-opcache php-apcu php8.0-fpm

Update PHP CLI configuration

sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/8.0/cli/php.ini
sed -i "s/display_errors = .*/display_errors = On/" /etc/php/8.0/cli/php.ini
sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/8.0/cli/php.ini
sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/8.0/cli/php.ini

Tweak PHP-FPM settings

Please note: We are suppressing PHP error output here by setting these options to production values

sed -i "s/error_reporting = .*/error_reporting = E_ALL \& ~E_NOTICE \& ~E_STRICT \& ~E_DEPRECATED/" /etc/php/8.0/fpm/php.ini
sed -i "s/display_errors = .*/display_errors = Off/" /etc/php/8.0/fpm/php.ini
sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/8.0/fpm/php.ini
sed -i "s/upload_max_filesize = .*/upload_max_filesize = 256M/" /etc/php/8.0/fpm/php.ini
sed -i "s/post_max_size = .*/post_max_size = 256M/" /etc/php/8.0/fpm/php.ini
sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/8.0/fpm/php.ini

Tune PHP-FPM pool settings

sed -i "s/;listen\.mode =.*/listen.mode = 0666/" /etc/php/8.0/fpm/pool.d/www.conf
sed -i "s/;request_terminate_timeout =.*/request_terminate_timeout = 60/" /etc/php/8.0/fpm/pool.d/www.conf
sed -i "s/pm\.max_children =.*/pm.max_children = 70/" /etc/php/8.0/fpm/pool.d/www.conf
sed -i "s/pm\.start_servers =.*/pm.start_servers = 20/" /etc/php/8.0/fpm/pool.d/www.conf
sed -i "s/pm\.min_spare_servers =.*/pm.min_spare_servers = 20/" /etc/php/8.0/fpm/pool.d/www.conf
sed -i "s/pm\.max_spare_servers =.*/pm.max_spare_servers = 35/" /etc/php/8.0/fpm/pool.d/www.conf
sed -i "s/;pm\.max_requests =.*/pm.max_requests = 500/" /etc/php/8.0/fpm/pool.d/www.conf

If you are using MongoDB

add extension=mongodb.so to PHP-fpm and PHP-cli configuration:

echo "extension=mongodb.so" > /etc/php/8.0/fpm/conf.d/30-mongodb.ini
echo "extension=mongodb.so" > /etc/php/8.0/cli/conf.d/30-mongodb.ini

Update your web server configuration to use php8.0-fpm

For Nginx you would edit /etc/nginx/sites-available/webdock. Look for this line and replace the PHP version number with the one you want:

fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;

For Apache you would edit /etc/apache2/sites-available/webdock.conf and /etc/apache2/sites-available/webdock-le-ssl.conf. Look for this line and replace the PHP version number with the one you want:

SetHandler "proxy:unix:/run/php/php8.0-fpm.sock|fcgi://localhost"

Reboot your server

After a reboot you should now be running on PHP version 8.0. You can check it by creating a small php file in your web root with the following contents and visiting it in your web browser:




Optional for LEMP Stacks: Upgrade Nginx to the latest version

As the Ondrej Sury Nginx PPA is no longer keeping up with the latest releases of Nginx you may experience that you are now stuck on version 1.19.0 - as the latest mainline builds of Nginx now include http2 by default, there is really no reason to use the Ondrej PPA anymore. 

In order to remove the Ondrej PPA and switch back to the mainline repository and get up to the latest version of Nginx, you can follow the below steps:

Remove the ondrej PPA

apt-add-repository --remove ppa:ondrej/nginx-mainline; apt update

Add the Nginx Mainline repository

echo "deb http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -

Now do a dist-upgrade in order to force the upgrade.

apt update; apt dist-upgrade -y

When apt asks you what to do about existing config files, you should choose the default (keep existing config)

This should be safe to do on Webdock stacks. If you are not on a Webdock stack, be aware that dist-upgrade may be a dangerous operation and that apt may remove packages you do not want removed. Use with caution in other contexts.!

Now you can check the version with

nginx -v

and you should be on the latest version. It is generally a good idea to reboot your server at this point to make sure everything comes up fresh.

We use cookies. Please see our Privacy Policy.