How to Install PHP 7.3 on Ubuntu 16.04

 In Dedicated, VPS, Web


  • In this tutorial, we will use an Ubuntu VPS with an already installed 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.


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


PHP (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, 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:

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://<>/phpinfo.php

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

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

Recommended Posts

Start typing and press Enter to search