PHP 7.4 is the latest stable release of PHP. Say thanks to Ondřej Surý for maintaining PPA of most the popular PHP versions on launchpad. If you want to install a specific version of PHP, then this article can be helpful for you. This article will help you to install PHP 7.4, 7.3, 7.2, 7.1 & PHP 7.0 on Ubuntu 18.04 LTS using PPA

Advertisement

You can also install multiple PHP versions on your system and switch PHP version between them. Also, you can configure Apache VirtualHosts to use different-2 PHP versions.

Install PHP 7.4 on Ubuntu

PHP 7.4 is the latest stable version is available for installation. 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 

PHP 7.4.5 (cli) (built: Apr 28 2020 14:49:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies

Install PHP 7.3 on Ubuntu

PHP 7.3 stable version has been released. Use the following set of commands to enable PPA for PHP 7.3 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.3

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

php -v 

PHP 7.3.9-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Sep  2 2019 12:54:04) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.9-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

Install PHP 7.2 on Ubuntu

PHP 7.2 stable version has been released. Use the following set of commands to enable PPA for PHP 7.2 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.2

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

php -v 

PHP 7.2.16-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Mar  7 2019 20:23:29) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.16-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

Install PHP 7.1 on Ubuntu

Use the following set of commands to add PPA for PHP 7 in your Ubuntu system and install PHP 7.1 version.

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

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

php -v 

PHP 7.1.27-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Mar  7 2019 20:02:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.27-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

Install PHP 7.0 on Ubuntu

Use the following set of commands to add PPA for PHP 7 in your Ubuntu system and install PHP 7.0 version.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php7.0

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

php -v 

PHP 7.0.33-5+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Mar  8 2019 09:49:15) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.33-5+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies

Install PHP 7 Modules

You may also need to install modules based on your application requirements. Use the following command to search available PHP 7 modules in the package repository.

sudo apt-cache search php7*
php-all-dev - package depending on all supported PHP development packages
php7.0 - server-side, HTML-embedded scripting language (metapackage)
php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.0-cli - command-line interpreter for the PHP scripting language
php7.0-common - documentation, examples and common module for PHP
php7.0-curl - CURL module for PHP
php7.0-dev - Files for PHP7.0 module development
php7.0-gd - GD module for PHP
php7.0-gmp - GMP module for PHP
...
...
...
php7.1-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP
php7.1-xmlrpc - XMLRPC-EPI module for PHP
php7.1-zip - Zip module for PHP
php7.1-opcache - Zend OpCache module for PHP
php7.1 - server-side, HTML-embedded scripting language (metapackage)
php7.1-xsl - XSL module for PHP (dummy)
...
...
php7.2-bcmath - Bcmath module for PHP
php7.2-bz2 - bzip2 module for PHP
php7.2-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.2-cli - command-line interpreter for the PHP scripting language
php7.2-common - documentation, examples and common module for PHP
php7.2-curl - CURL module for PHP
php7.2-dba - DBA module for PHP

You can install the required PHP modules on your system as below command. Make sure to install packages for correct PHP version by specifying the version with the package name. Without defining the package version, it will install the latest package.

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

Congratulation! Enjoy the development with PHP 7.

Share.

48 Comments

  1. Hello, I’m setting a new server for a website on ubuntu 18.04 and when I install php 7.1 with ondrej ppa it installs php7.1-mapi
    “Note, selecting ‘php7.1-mapi’ for regex ‘php7.1′”
    I tried 7.0 or 7.3 and it says : “E: Unable to locate package php7.3
    E: Couldn’t find any package by glob ‘php7.3’
    E: Couldn’t find any package by regex ‘php7.3′”
    Last year I already installed ondrej ppa with 7.1 on another server ubuntu 18.04 and it worked fine. Now it won’t there’s only php 7.2 and as there are compatiblities issues, I want the 7.1.

  2. Thanks for providing install instructions to the newer php7.4.5 I couldn’t find how to install it anywhere. This article helped. A lot.

  3. Pleas help me to solve this problem.! i’m beginner

    You might want to run ‘apt –fix-broken install’ to correct these.
    The following packages have unmet dependencies:
    default-jre-headless : Depends: openjdk-11-jre-headless
    hhvm : Depends: libboost-context1.65.1 but it is not going to be installed
    Depends: libboost-program-options1.65.1 but it is not going to be installed
    Depends: libdwarf1 (>= 20160507+git20160523.9086738) but it is not going to be installed
    Depends: libgoogle-glog0v5 but it is not going to be installed
    Depends: libjemalloc1 (>= 3.5.0) but it is not going to be installed
    Depends: libmcrypt4 but it is not going to be installed
    Depends: libmemcached11 but it is not going to be installed
    Depends: libodbc1 (>= 2.3.1) but it is not going to be installed
    Depends: libonig4 (>= 5.9.5) but it is not going to be installed
    Depends: libre2-4 (>= 20160901) but it is not going to be installed
    Depends: libtbb2 but it is not going to be installed
    openjdk-11-jre : Depends: openjdk-11-jre-headless (= 11.0.2+9-3ubuntu1~18.04.3)
    E: Unmet dependencies. Try ‘apt –fix-broken install’ with no packages (or specify a solution).

  4. Getting this on sudo apt-get install php7.2

    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package php7.2
    E: Couldn’t find any package by regex ‘php7.2’

      • This is the error message I’m getting with Ubuntu 16.04. I don’t know what version Vishwas was using though. Thank you for your valuable help in making the world a better place!

  5. hi,
    can you suggest me how to install php7.1-curl in ubuntu 14.04?

    i have tried many ways but cannot find the ext curl in repo. please help me sir.

  6. Hi,

    Can you please let me know, how to install php7.1.33 in Ubuntu 16.04 server.

    I tried with the above solution but from this solution, I can install only 7.1.26.

    Please suggest.

    Regards;
    Manoj Gupta

  7. hello is there any way to upgrade php 7.2 to 7.3? i’m currently running php 7.2 want to upgrade to php 7.3 but i’m afraid breaking the system

  8. Isaac Rosario Durán on

    I need some help. I can’t instll some extensions on PHP (Ubuntu server v18) MBString and ZIP.
    When i try to install i got the follow error.

    —– Error below —–

    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package php7.2-mbstring
    E: Couldn’t find any package by glob ‘php7.2-mbstring’
    E: Couldn’t find any package by regex ‘php7.2-mbstring’
    E: Unable to locate package php7.2-zip
    E: Couldn’t find any package by glob ‘php7.2-zip’
    E: Couldn’t find any package by regex ‘php7.2-zip’

  9. Mayank jadeja on

    Hello,
    Is there any way by which I can install php 7.1.0 or 7.0.2 in Ubuntu 18.04.
    As i want to work on Magento 2 & its not compatible with PHP versions like 7.2.x , 7.1.1 or 7.0.3

  10. hello there is an update(7.2.1 ) on jan 4 2018/ how to upgrade from php.net launch pad net not working.

    getting count() issues
    PHP Warning: count(): Parameter must be an array or an object that implements Countable

    • Yes, simply upgrade to PHP 7.2.1 also not worked for me. So I removed current version

      apt purge php7.2*

      and install it again with all required modules. It worked for me.

      apt install php7.2

  11. Anjanesh Lekshminarayanan on

    How do I setup my Apache’s directory’s .htaccess in such a way that for this specific directory execute php7.1 for .php files ?

  12. Hi Rahul, is it good to install the PHP 7.1 for the production use, because i heared we cant find any library files for the latest version of PHP.

  13. Adding the repository results in the following message:

    “PLEASE DON’T USE PHP 5.4 OR PHP 5.5. The PHP 5.5 and later are no longer supported with security updates, therefore they are not included in this repository.”

    I think you meant to say: “The PHP 5.5 and EARLIER are no longer supported . . . .” Right?

  14. Rahul, could you please update the article to point to ppa:ondrej/php, I will be deprecating php-7.0 as the co-installable repository is working just fine, so I am just building the same packages twice. I am trying to hunt down all the popular articles around, so I could kill the ppa:ondrej/php-7.0.

    Thanks,
    Ondrej

  15. Hi,

    it is posible to use two version of php – 5.6 and 7 ?
    5.6 for deployment and 7 for experiments in CLI or separated php7-fpm server.

    Thank you.

    • Sure, ppa:ondrej/php contains both PHP 5.6 and 7.0 that could be installed together. You just cannot enable both PHP Apache modules at the same time.

Exit mobile version