How to Install PHP 7.3 on Ubuntu 16.04

Install PHP 7.3 on Ubuntu 16

In this article, we will show you how to install PHP 7.3 on Ubuntu 16.04. PHP (Hypertext Preprocessor) is an open-source server-side scripting language and is widely used for creating dynamic web pages. PHP is among the most popular languages because it is secure, fast, simple, efficient, flexible, and a loosely typed language.

install php 7.3 ubuntu 16.04


PHP can be run on any operating platform (Windows, Linux, MacOS) and almost on any web server (Nginx, Apache). PHP 7.3.0 was officially released on December 6, 2018, and it contains new improved features and functions.

For more updates, you can also check our guide on how to install PHP 8 on Ubuntu 20.04

Requirements:

  • In this tutorial, we will use an Ubuntu VPS with an already installed LAMP stack, because our Ubuntu 16.04 VPS has been pre-installed with a fully working LAMP stack. However, if you do this on a clean server, we will show you how to install Apache’s web server during this tutorial.
  • A user with sudo privileges or root is required.

Step 1: Connect to your server via SSH and update your server OS packages

The first thing to do is to connect to your VPS via SSH as a user with root privileges or a root user.

ssh root@SERVER_IP_ADDRESS -p PORT_NUMBER

Just replace the “SERVER_IP_ADDRESS” and “PORT_NUMBER” with your actual server IP address and port number.
Please note that if you want to connect to a user who has root privileges, simply change the ‘root’ user with the user you want to use.

Once logged in, you can update your Ubuntu OS packages to the latest version using:

apt update && apt upgrade

If you have a new Linux VPS and you are not familiar with the procedure on how to manage your server then you should definitely check our article Connecting via SSH to your server.

Step 2: Install a Web Server

In this step, we will install a web server. You can choose between Apache or Nginx because both are fast, secure, and reliable. In this tutorial, we will use Apache which is the most popular among web servers.

To install Apache web server, run the following command on your server:

apt install apache2

After installing Apache2, use the command below to start the Apache service:

systemctl start apache2

Also, you can enable Apache server to always startup when the server boots up:

systemctl enable apache2

You can always check the status of the Apache web service with this command:

systemctl status apache2

You can also open your favorite browser and enter your IP address (for example http://your_server_ip_address), and check whether Apache is running on your server.
If you see the Apache’s default welcome page it means that the Apache web server is successfully installed and running.

Step 3: Install Ondřej Surý’s PPA repository

We will use the Ondřej Surý’s PPA to install PHP 7.3 version, so install the software-properties-common and python-software-properties packages:

apt install software-properties-common python-software-properties

After the installation is complete, add the Ondřej PPA:

LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php

and then update your sources:

apt update

Step 4: Install PHP 7.3

We can install PHP 7.3 with the following command:

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

To check if PHP 7.3 is installed on your server, use the command below:

php -v

Output:

PHP 7.3.0-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Dec 6 2018 20:24:27) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.0-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

Step 5: Install specific PHP 7.3 extensions

If you want to install a specific module for PHP 7.3, you can search with this command:

apt-cache search php7.3

Or, if you want to check all the PHP modules available in Ubuntu, run:

apt-cache search --names-only ^php

You can find the command below useful if you want to install the most frequently used PHP modules.

apt install php-pear php7.3-curl php7.3-dev php7.3-gd php7.3-mbstring php7.3-zip php7.3-mysql php7.3-xml php7.3-fpm libapache2-mod-php7.3 php7.3-imagick php7.3-recode php7.3-tidy php7.3-xmlrpc php7.3-intl

Step 6: Change the PHP version

In this step from our article, we will show you how you can change which version of PHP to be the default if you have multiple versions of PHP installed on your Ubuntu server.

To set PHP 7.0 as the default, run:

update-alternatives --set php /usr/bin/php7.0

To set PHP 7.2 as the default, run:

update-alternatives --set php /usr/bin/php7.2

To set PHP 7.3 as the default, run:

update-alternatives --set php /usr/bin/php7.3

Before we can configure Apache to use PHP 7.3, we need to disable the old version of PHP 7.0 by typing:

a2dismod php7.0

Now enable the newly installed PHP 7.3 version with the following command:

a2enmod php7.3

Restart the Apache web server for the changes to take effect:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
systemctl restart apache2

Step 7: Test and verify your PHP version

We can test the PHP version, Apache PHP and PHP modules with a simple PHP info file. We can create a phpinfo.php file in the web server default directory and access it with your server IP address on your favorite browser.
In our example, we are using Apache web server so the default directory is located at /var/www/html/ .

nano /var/www/html/phpinfo.php

Add the following code to it:

<?php phpinfo(); ?>

Open the ‘phpinfo.php’ file using a web browser:

http://<ip_address>/phpinfo.php or http://<your_domain.com>/phpinfo.php

You should be able to view the current information about PHP on your server.

php7.3

Congratulations, you have successfully installed PHP 7.3 on an Ubuntu 16.04 server. For more detailed information about PHP 7.3, you can check the official PHP documentation.


Of course, you don’t have to install PHP 7.3 on Ubuntu 16.04, if you use one of our Managed PHP Hosting services, in which case you can simply ask our expert system administrators to install PHP 7.3 on Ubuntu 16.04 for you, using the LAMP or LEMP stack or any other web hosting stack of your choice. They are available 24×7 and will take care of your request immediately.

ubuntu 16.04 install php 7.3

PS. If you liked this post, on how to install PHP 7.3 on an Ubuntu 16.04 server, please share it with your friends on social networks or simply leave a comment in the comments section. Thanks.

10 thoughts on “How to Install PHP 7.3 on Ubuntu 16.04”

    • Hi Slava,

      Yes, the line is correct. If you don’t set the locales, you will get a message that the repository is broken with non-UTF-8 locales.

      Reply
  1. I have php7.0 in production.

    I have followed your steps to upgrade to 7.3, but it does not install php7.3

    ubuntu@ip-172-31-37-133:~$ sudo apt install php7.3
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Note, selecting ‘php7.3-ssh2’ for regex ‘php7.3’
    Note, selecting ‘php-ssh2’ instead of ‘php7.3-ssh2’
    php-ssh2 is already the newest version (1.2+0.13-1+ubuntu16.04.1+deb.sury.org+1).
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    ubuntu@ip-172-31-37-133:~$

    Any ideas?

    Reply
  2. I have followed all the steps in the article, including step 3.
    This is what I get on executing “sudo add-apt-repository ppa:ondrej/php”

    Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don’t ask for end-of-life PHP versions or Ubuntu release, they won’t be provided.

    Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa

    You can get more information about the packages at https://deb.sury.org

    IMPORTANT: The -backports is now required on older Ubuntu releases.

    Reply
    • It seems that PHP dropped the support for Ubuntu 16.04. You should use the latest version of Ubuntu since Ubuntu 16.04 is no longer supported.

      Reply

Leave a Comment