How to upgrade to PHP 7.3 on Ubuntu

PHP 7.3 has a lot of performance advantages compared to 7.2 and co among other bug fixes. Since performance is one of my main reason why I wanted to upgrade to PHP 7.3 on my Ubuntu server I am going to share how you can upgrade to PHP 7.3 on Ubuntu. My machine run Ubuntu 18.04 but I have performed this upgrade even on lower versions like Ubuntu 16.04 without any problems.

Let’s get started.

WARNING

Because PHP 7.3 is not yet officially released, there can be several bugs and other kind of issues since once again its not official yet. I highly recommend you not upgrade your production servers to PHP 7.3 yet.

1. Add ondrej/php PPA

We are going to use PHP PPA by Ondrej. He has published PHP 7.3 on all supported Ubuntu versions.

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

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

sudo apt-get install php7.3-curl php7.3-gd php7.3-intl php7.3-bcmath php7.3-imap php7.3-json php7.3-mysql php7.3-oauth php7.3-readline php7.3-bz2 php7.3-mbstring php7.3-opcache 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
Activate php7.3 Apache module
sudo a2enmod php7.3
Issue update and upgrade command
sudo apt-get update
sudo apt-get upgrade

Leave a Comment