How to install PHP 8.0, 7.4, 7.3 or 7.2 on Ubuntu 16.04 | 18.04 | 20.04

PHP is a general-reason programming language originally designed for net development. It was in the beginning created by using Rasmus Lerdorf in 1994 the PHP reference implementation is now produced by means of The PHP Group. PHP firstly stood for Personal Home Page, however it now stands for the recursive initialism PHP: Hypertext Preprocessor, To get more information click here.

In this Article, We will install PHP 8.0, 7.4, 7.3, 7.2 on ubuntu 16.04 / 18.04

 
Add the PHP Repository 

To add the PHP 8.0 repo in ubuntu, Use the following commands with root privileges.

sudo -i

add-apt-repository ppa:ondrej/php


Install PHP 8.0

To install PHP 8.0, We need to update the ubuntu current repository and after that We need to install PHP 8.0 by following the commands. 

apt-get update

apt-get install php8.0 -y

Check PHP Version

To verify the PHP use the following commands.

php -v



Add the PHP Repository 

To add the PHP 7.4 repo in ubuntu, Use the following commands with root privileges.

sudo -i

apt-get install software-properties-common

add-apt-repository ppa:ondrej/php

Install PHP 7.4 

To install PHP 7.4, We need to update the ubuntu current repository and after that We need to install PHP 7.4 by following the commands. 

apt-get update

apt-get install php7.4 -y

Check PHP Version

To verify the PHP use the following commands.

php -v



You should get output like this.

PHP 7.4.1 (cli) (built: Dec 18 2019 14:44:04) ( NTS )

Copyright (c) The PHP Group

Zend Engine v3.4.0, Copyright (c) Zend Technologies

    with Zend OPcache v7.4.1, Copyright (c), by Zend Technologies



Install PHP modules 

Once installed PHP 7.4 on ubuntu machine, We required some PHP modules to make connectivity with mysql, zip, pear and more, To install PHP modules use the following commands.


apt-get install  php7.4-curl php-pear  php7.4-gd  php7.4-dev  php7.4-zip php7.4-mbstring php7.4-mysql php7.4-xml

To check installed PHP modules in your machine use the following commands.

php -m 

How to install PHP 7.3 on ubutnu 16.04

To add the PHP 7.3 repo in ubuntu, Use the following commands with root privileges.

sudo -i

apt-get install software-properties-common

add-apt-repository ppa:ondrej/php

Install PHP 7.3 

To install PHP 7.3, We need to update the ubuntu current repository and after that We need to install PHP 7.3 by following the commands. 

apt-get update

apt-get install php7.3 -y

Check PHP Version

To verify the PHP use the following commands.

php -v



You should get output like this.

PHP 7.3.13-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Dec 18 2019 14:48:32) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.13, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.13-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies



Install PHP modules 

Once installed PHP 7.3 on ubuntu machine, We required some PHP modules to make connectivity with mysql, zip, pear and more, To install PHP modules use the following commands.


apt-get install  php7.3-curl php-pear  php7.3-gd  php7.3-dev  php7.3-zip php7.3-mbstring php7.3-mysql php7.3-xml

To check installed PHP modules in your machine use the following commands.

php -m 

How to install PHP 7.2 on ubutnu 16.04

To add the PHP 7.2 repo in ubuntu, Use the following commands with root privileges.

sudo -i

apt-get install software-properties-common

add-apt-repository ppa:ondrej/php

Install PHP 7.2 

To install PHP 7.2, We need to update the ubuntu current repository and after that We need to install PHP 7.3 by following the commands. 

apt-get update

apt-get install php7.2 -y

Check PHP Version

To verify the PHP use the following commands.

php -v

You should get output like this.

PHP 7.2.26-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Dec 18 2019 14:57:40) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies



    with Zend OPcache v7.2.26-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

Install PHP modules 

Once installed PHP 7.2 on ubuntu machine, We required some PHP modules to make connectivity with mysql, zip, pear and more, To install PHP modules use the following commands.


apt-get install php-pear  php7.2-gd  php7.2-dev  php7.2-zip php7.2-mbstring php7.2-mysql php7.2-xml php7.2-curl 

To check installed PHP modules in your machine use the following commands.

php -m 




How to install PHP 8.0, 7.4, 7.3 or 7.2 on Ubuntu 16.04 | 18.04 | 20.04

3 thoughts on “How to install PHP 8.0, 7.4, 7.3 or 7.2 on Ubuntu 16.04 | 18.04 | 20.04

  1. Ondrej's Repo no longer supplies packages for 16.04 Xenial as it is EOL.
    Unfortunately, it's the last Ubuntu release which can run run on OpenVZ 6 which many VPS hosts still use despite it also being EOL for quite a while.
    It is still possible to build the latest release of PHP 7.x (7.4.27) from source code on Ubuntu 16.04 though and with FPM it can also be used with webservers.
    Building from source is more complicated than adding a PPA though.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top