Configuring Debian 11 Servers For PHP 8.1

This tutorial explains configuring Debian 11 for PHP 8.1 on your new or existing web application server. PHP applications such as WordPress or Nextcloud often track their supported PHP version with the version bundled with the most recent LTS Ubuntu Server release. For those who prefer Debian over Ubuntu (there are good reasons to do so – I’ll be detailing these in an upcoming article so check back for it!) instead, configuring Debian 11 for PHP 8.1 keeps parity with Ubuntu and ensures the best possible performance or compatibility for your PHP based applications.

Before We Begin

Consider this my due diligence in reminding you to properly go about making changes to your servers.

If You’re Updating A Production Server


It’s likely your server exists as a VM or container of some kind. Instead of making a direct update to your production server, instead create a snapshot of your server, then create a clone from that snapshot. Then apply your updates. Lastly, replace the production server with the newly updated server.

If you are willing to risk a small amount of downtime, you could skip working on a clone of your server. Only do this though if you have a snapshot or backup that can be quickly rolled back if needed.

If You Absolutely MUST Update A Production Server

Seriously – don’t ever make a configuration change to a production server unless you can afford to experience downtime if things go sideways. If you have absolutely no choice but to update a production server without some form of snapshot or easily recoverable backup …

  • Who the hell setup your server?
  • You’ve been warned.

Getting Started

It’s always a good idea to start off any kind of Debian software configuration with a full system update / upgrade.

sudo apt update && sudo apt upgrade -y

Once that finishes, we’re going to make sure we have any and all dependencies installed.

sudo apt-get install apt-transport-https ca-certificates curl lsb-release software-properties-common wget -y

Now we’re ready to add the necessary software repository.

Configuring Debian 11 With A New Repository

For those who aren’t familiar with Ondřej Surý, he’s pretty much the maintainer of PHP for Debian & Ubuntu. So while his repository that we’re about to add isn’t officially from either Debian or Ubuntu, this is as official as it gets when it comes to a 3rd party source.

curl -sSL | sudo bash -x

It’ll look something like this as it’s running.

Terminal Screenshot - Configuring Debian 11 with PHP 8.1

Once you’ve done this, you need to update the package database for the new repository’s packages to be available.

sudo apt update

We’re now ready to either update your existing PHP install to version 8.1 or install PHP on your new Debian server.

Upgrade Debian (Again)

On a Debian server with an already existing PHP 7.4 installation, the only thing you need to do now in order to upgrade your installed packages is to run an apt upgrade.

sudo apt upgrade -y

Important to note – this WILL completely remove your pre-existing PHP install. If you need to run both versions of PHP, you can do so by installing PHP 7.4 specifically. Example:

sudo apt install php7.4 php7.4-fpm php7.4-cli

Update Your Web Server Configuration

Once you’ve updated PHP, you’ll want to ensure your web server configs (ex: Apache or Nginx) are updated to look for the new version of PHP.

For example, with Nginx you’d want to update a line like this inside of a domain’s sites-available configuration …

fastcgi_pass unix:/run/php/php7.4-fpm.sock;

… to look this instead …

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

Installing PHP 8.1 On New Servers

If you’re setting up a brand new Debian based server, after configuring the new PHP repository, your setup commands / bash scripts / Ansible playbooks – whatever method you use to configure your server – will pull down the updated packages instead of the standard versions that come from Debian – so long as you aren’t specifying the version in the commands. For example …

sudo apt install php php-fpm php-cli

… will install the updated version whereas …

sudo apt install php7.4 php7.4-fpm php7.4-cli

… will install the older version instead.

As this isn’t a post explaining how to setup a LAMP or LEMP server, I’ll not be walking through how exactly to configure your new server here. However, for those who are unfamiliar with how to do this already, watch for future content on exactly how to setup your own web servers.


Congratulations! Your Debian server now runs PHP 8.1. If everything went according to plan, your upgrade should only have taken a few minutes to complete … and you didn’t update your live production server in order to avoid downtime, right?

If you found this tutorial helpful or have any questions, I encourage you to please share ite with others and/or leave a comment below. If you would like to support our efforts to create additional resources like this, please consider making a donation. Your support is greatly appreciated! Thanks for reading and I hope you visit again soon!

Leave a Comment

Your email address will not be published. Required fields are marked *

I accept the Privacy Policy

Scroll to Top