Install PHP 8.1 FPM on Ubuntu 18.04 for WordPress

The PHP 8 benchmarks are looking really sexy! More performance improvements are always welcome over PHP 7.4 🙂

Check out this in-depth list of the new PHP 8 features.

Remember to test the new PHP 8.1 in a staging environment for your WordPress or WooCommerce site first, ideally on a separate server. If you need help testing this feel free to get in touch.

This tutorial will show you how to install PHP 8.0 on Ubuntu 18.04 and update the CLI path to use the new PHP version.

Install PHP 8.1 php-fpm on Ubuntu 18.04

Start with adding the repository kindly provided by sury.org

sudo apt-get install apt-transport-https -y
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list

Update your package list

sudo apt-get update

Install the PHP 8.1 packages for nginx and php-fpm functionality

sudo apt-get install sudo php8.1-cli php8.1-curl php8.1-mysql php8.1-fpm php8.1-gd php8.1-xml php8.1-mbstring php8.1-zip php8.1-soap php8.1-dev -y

Now we can update the PHP command line binary shorthand php to use the PHP 8.1 CLI binary.

Update PHP CLI to 8.1

Test your current PHP CLI version with this command

php --version

Output here is showing PHP 7.4!

PHP 7.4.13 (cli) (built: Nov 28 2020 06:24:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies

Update the CLI shortcut to use the 8.0 binary with this command

sudo update-alternatives --set php /usr/bin/php8.1

Now make sure it worked

php --version

Output is now showing PHP 8.1 🙂

php --version
PHP 8.1.9 (cli) (built: Aug 15 2022 09:39:35) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.9, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.9, Copyright (c), by Zend Technologies

Remember to configure PHP-FPM for low memory consumption with this guide.