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.
PHP can be run in 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.
- 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.
Table of Contents
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 [email protected]_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 the 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:
Recommended Reading: How to Install MySQL 5.7 on Ubuntu 16.04
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 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:
Now enable the newly installed PHP 7.3 version with the following command:
Restart the Apache webserver 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 the Apache web server so the default directory is located at /var/www/html/ .
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.
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.