Install/Upgrade to PHP 7.3 - Ubuntu & Debian

Published On2018-11-07

Upgrade to PHP 7.3 on Ubuntu and Debian

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 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.

3. 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.

Recent Articles on PHP.Watch

All ArticlesFeed 
How to extend lifetime of legacy PHP applications

How to extend lifetime of legacy PHP applications

As PHP continue to evolve with new breaking changes, and while that is great for most PHP applications, there are legacy applications that can't justify the human and financial cost of keeping up. Here is a guide on how to extend the lifetime of legacy PHP applications with security updates and maintenance.
PHP 8.2 Highlights: What's New and Changed

PHP 8.2 Highlights: What's New and Changed

Read about the highlights of PHP 8.2: Major new features, changes, and deprecated functionality.
How to install/upgrade PHP 8.2 on Debian and Ubuntu systems

How to install/upgrade PHP 8.2 on Debian and Ubuntu systems

A detailed and a quick-start guide on installing and upgrading PHP 8.2 on Debian and Ubuntu systems
Subscribe to PHP.Watch newsletter for monthly updates

You will receive an email on last Wednesday of every month and on major PHP releases with new articles related to PHP, upcoming changes, new features and what's changing in the language. No marketing emails, no selling of your contacts, no click-tracking, and one-click instant unsubscribe from any email you receive.