Install/Upgrade to PHP 7.3 - Ubuntu & Debian

Tue, 2018-11-06 12:56

I wrote posts about updating Debian & Ubuntu systems to PHP 7.1 and 7.2. It's time for a similar post for PHP 7.3. PHP 7.3 is expected to be released on December 6, but I have been trying it out for a few months now. You can also take a look at What's new and changing in PHP 7.3 that turned out to be a quite comprehensive list of what's new, deprecated, and changed in PHP 7.3. This guide is pretty much similar to the PHP 7.1 and 7.2 upgrade guides.

SCARING WARNING

Because PHP 7.3 is not released to the masses yet, there can be several bugs in it, I highly recommend you not upgrade your production servers to PHP 7.3 yet. I have personally come across a few mysterious bugs myself, so be warned.

1. Add ondrej/php PPA

As usual, we use the awesome PHP PPA by Ondrej. He publishes PHP 7.3 on all supported Ubuntu versions and Debian Stretch and Jessie.

Ubuntu

sudo add-apt-repository ppa:ondrej/php # Press enter to confirm.
sudo apt-get update

Debian

sudo apt install apt-transport-https lsb-release
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg # Download the signing key
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' # Add Ondrej's repo to sources list.
sudo apt update

2. Note down current PHP packages

If you are upgrading PHP from an earlier version, it's important to make sure you ensure you have the same PHP extensions installed. PHP 7.2 onwards no longer include mcrypt extension. Other than that, PHP 7.3 includes all extensions that were in PHP 7.1 and 7.2.

dpkg -l | grep php | tee packages.txt

Above command will list all packages installed in your system that has php in its name, and write them to a file called packages.txt in your current working directory. You can easily refer this file to install the same PHP 7.3 package counter parts.

2. Install PHP 7.3

Now to the juicy part!

PHP 7.3 core

sudo apt install php7.3 php7.3-common php7.3-cli

This will install PHP 7.3 core extensions and PHP 7.3 CLI.

PHP 7.3 extensions

You can now install the remaining packages as necessary. If you are setting up a new setup, or have no clear idea which packages to install, I highly recommend installing the following packages from the command below. If you are upgrading, look at the packages.txt file to see your current list.

apt install php7.3-bcmath php7.3-bz2 php7.3-curl php7.3-gd php7.3-intl php7.3-json php7.3-mbstring php7.3-readline php7.3-xml php7.3-zip

PHP 7.3 for web server

With all these packages in place, you might also need to integrate PHP with your web server. If you are using Nginx, or Apache with mod_event, you will need to install php7.3-fpm package. If you are using PHP as an embedded Apache module, you will need libapache2-mod-php7.3 package. For Apache, you can run apachectl -V to see your current MPM, whether its prefork or event.

Nginx and Apache with event MPM

apt install php7.3-fpm

Apache with prefork MPM

apt install libapache2-mod-php7.3

3. Test if PHP 7.3 is properly installed

Once everything is installed, run php -v to make sure PHP 7.3 (CLI) is installed.

Output of PHP 7.3 'php -v' command.

4. Remove old PHP versions

With new PHP 7.3 installed, you can remove your old PHP versions if you want.

apt purge php7.2 php7.2-common # Change 7.2 with whatever current version you have.

So that's it, you should have PHP 7.3 running. Note that automatic upgrades (unattended-upgrades) will not work on Ondrej's PPA, so you still need to manually upgrade your PHP versions. Make sure to run apt update and apt upgrade to upgrade to the latest PHP version.

If you run into unexpected bugs related to PHP 7.3, see What's new and changing in PHP 7.3 that might answer what caused the surprise.