Install PHP 7.3 on Ubuntu 18.04 - Step by Step Process ?

PHP is most popular and widely used open-source server-side scripting language in the world. PHP is available in various versions and PHP 7.3 is the latest version of PHP.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related PHP queries.

In this context, we shall look into how to install a specific version of PHP. In this guide outlines how to install PHP 7.3 on Ubuntu 18.04.


How to Install PHP 7.3 on Ubuntu ?

Before proceeding with this Installation procedure, you need Ubuntu server with a non-root user account and make sure that you have full root access.

At First, update the apt package list and upgrade the software currently installed on the server to the latest version using below commands:

$ sudo apt-get update
$ sudo apt-get upgrade

Once your system is fully up to date, we can now proceed with the PHP 7.3 installation.


PHP 7.3 is available from ondrej/php PPA repository. PHP 7.3 stable version has been released with many new features and bug fixes. You can get latest news from PHP releases news.

First, we will add PPA repository for PHP 7.3 and update index list using below commands:

$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt update

You can add PPA manually to your Ubuntu 18.04 system by copying the lines below and adding them to your system's software sources.

deb http://ppa.launchpad.net/ondrej/php/ubuntu bionic main
deb-src http://ppa.launchpad.net/ondrej/php/ubuntu bionic main


How to Install PHP 7.3 With Extensions ?

Once PPA repository added, you can install PHP 7.3 with some of the most commonly used extensions by executing below command:

$ sudo apt install php7.3 php7.3-cli php7.3-common php7.3-opcache php7.3-curl php7.3-mbstring php7.3-mysql php7.3-zip php7.3-xml


How to Verify PHP Installation ?

After completion of PHP installation you can verify installed PHP version with below command which will print the PHP version with details:

$ php -v
PHP 7.3.3-1+0~20190307202245.32+stretch~1.gbp32ebb2 (cli) (built: Mar  7 2019 20:22:46) ( NTS )
 Copyright (c) 1997-2018 The PHP Group
 Zend Engine v3.3.3, Copyright (c) 1998-2018 Zend Technologies
     with Zend OPcache v7.3.3-1+0~20190307202245.32+stretch~1.gbp32ebb2, Copyright (c) 1999-2018, by Zend Technologies


How to Configure Apache to run PHP ?

If you are using Apache web server to install PHP then you need to install Apache PHP modules by following commands :

$ sudo apt install php7.3 libapache2-mod-php

After that, you need to restart Apache service to enable the php modules :

$ sudo systemctl restart apache2


How to Configure Nginx to run PHP ?

Since Nginx does not contain native PHP processing like some other web servers, so we will need to install fpm ("fastCGI process manager") which will handle PHP files:

$ sudo apt install php7.3-fpm

Once installation is complete the fpm service will start automatically. You can also check status by executing below command :

$ sudo systemctl status php7.3-fpm

Now edit your website nginx server block and add following lines to so Nginx can process PHP files :

server {
    #... other code
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }
    #... other code
}

To take effect of new configuration need to restart Nginx service by following command :

$ sudo systemctl restart nginx


[Need assistance in fixing PHP Installation errors in Debian Linux System ? We can help you. ]

This article covers how to install PHP 7.3 on Ubuntu 18.04 server. Also, you will learn how to configure PHP with Apache and Nginx web servers. 


How to Install PHP 7.4 on Ubuntu ?

Use the following set of commands to enable PPA for PHP 7.4 in your Ubuntu system and install it. You can use this version for production use also.

$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get install -y php7.4

Now use the following command to check installed php version on your system.

$ php -v 


How to Install PHP 7 Modules ?

You can install the required PHP modules on your system as below command:

$ sudo apt-get install php7.2-mysql php7.2-curl php7.2-json php7.2-cgi php7.2-xsl

Related Posts