How to Install PHP 7.3 on Debian 9: the Sury Repository, Modules and Switching Your Site
Debian 9 installs PHP 7.0 by default. That’s already good: according to the PHP developers, PHP 7 is up to twice as fast as PHP 5.6, and you could stop right there.
But you always want more, don’t you? And there is a way!
You can install PHP 7.1, 7.2 or 7.3, and it’s version 7.3 that gives the best speed. Besides, official support for PHP 7.0 already ended on 10 January 2019.
According to various figures I found online, upgrading from PHP 7.0 to PHP 7.3 gives roughly a 20–25% speed boost. Of course, the gain depends on what code you run, but there should be one, so why not install the latest version right away?
If you can upgrade the server to Debian 10 (released in July 2019), you don’t need a third-party repository: PHP 7.3 comes with it out of the box.
Installing PHP 7.3 on Debian 9
I give all the commands without sudo, as root.
1. Update the current packages
apt update apt upgrade
2. Add the Sury repository with newer PHP versions
Install the required packages, import the signing key and add the repository:
apt install ca-certificates \ apt-transport-https wget SURY=https://packages.sury.org/php cd /tmp wget -q $SURY/apt.gpg apt-key add apt.gpg echo "deb $SURY/ stretch main" \ > /etc/apt/sources.list.d/php.list apt update
3. Install PHP 7.3
The important choice here is how PHP works with your web server. The php7.3 package on its own pulls in the Apache module and with it the Apache web server itself, so for Nginx or PHP-FPM install FPM directly:
apt install php7.3-fpm
If PHP runs as an Apache module:
apt install php7.3 \ libapache2-mod-php7.3
4. Install the modules
A set that WordPress and most websites need:
apt install php7.3-cli php7.3-curl \ php7.3-mbstring php7.3-mysql \ php7.3-xml php7.3-gd php7.3-bcmath \ php7.3-imagick php7.3-opcache
Without php7.3-gd or php7.3-imagick, WordPress stops creating resized copies of images – I ran into this myself, details in the post “WordPress Stopped Resizing Images to 600 px”.
5. Carry over your php.ini settings
Each version has its own settings files: /etc/php/7.3/fpm/php.ini for FPM and /etc/php/7.3/apache2/php.ini for the Apache module. If you changed limits in /etc/php/7.0/ (memory_limit, upload_max_filesize and so on), copy them to the new files.
6. Switch the site to PHP 7.3
Apache module:
a2dismod php7.0 a2enmod php7.3 systemctl restart apache2
Nginx + PHP-FPM: in the site config, point to the new socket (the line can be split, Nginx allows it):
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
and restart:
systemctl restart php7.3-fpm systemctl reload nginx
The service is called exactly php7.3-fpm, with the version in its name. A command without the version (php-fpm) won’t find the service.
Apache + PHP-FPM (the a2disconf line is only needed if you used 7.0 with FPM):
a2enmod proxy_fcgi setenvif a2disconf php7.0-fpm a2enconf php7.3-fpm systemctl restart apache2
7. Check and remove the old version
php -v
If the console still shows 7.0, set the default version:
update-alternatives --set php \ /usr/bin/php7.3
Remove the old PHP only after your sites are running on 7.3. If you keep several PHP versions for different sites, leave the old one alone:
apt purge 'php7.0*'
Enjoy the new, fast PHP 7.3!
As of November 2026
These instructions no longer work: Debian 9 has been moved to the archive and gets no updates, the Sury repository for stretch has been removed, and support for PHP 7.3 ended on 6 December 2021.
Today Debian 13 ships PHP 8.4 out of the box, with security fixes until 31 December 2028, so most sites don’t need a third-party repository:
apt install php8.4-fpm
If you need a newer version (PHP 8.5, for example) or another PHP version on Debian 11–13, Sury can still be added, but now with its own keyring package:
apt update apt install lsb-release \ ca-certificates curl SURY=https://packages.sury.org curl -sSLo /tmp/sury.deb \ $SURY/debsuryorg-archive-keyring.deb dpkg -i /tmp/sury.deb K=/usr/share/keyrings K=$K/debsuryorg-archive-keyring.gpg CODE=$(lsb_release -sc) L="deb [signed-by=$K]" L="$L $SURY/php/ $CODE main" F=/etc/apt/sources.list.d/php.list echo "$L" > $F apt update apt install php8.5-fpm
Need a VPS to practice on? On Vultr you can spin up a Debian server with hourly billing, try different PHP versions and delete it when you’re done (affiliate link).
