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
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.
48 Comments
what is php service to check is running after installation and modules installation
Thanks for the post!
After adding ondrej repository,
I ran the update command, but I get this error:
Hit:1 https://packages.sury.org/php stretch InRelease
Ign:2 http://ppa.launchpad.net/ondrej/php/ubuntu hirsute InRelease
Err:3 http://ppa.launchpad.net/ondrej/php/ubuntu hirsute Release
404 Not Found
Reading package lists… Done
Please is there a solution to this ?
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.
thank you very much!
Thank you so much !
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.
`apt-get` > just `apt`
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).
Thanks. It’s so usefull.
Gracias.. Muy util. Saludos.
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’
Which Ubuntu version are you using?
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!
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.
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
thanks for valubal answer
LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
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
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’
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
The Brazil thanks you.
If you are installing PHP 7.2 on a server, then I would recommend using Cloudways for it. This php 7.2 hosting (https://www.cloudways.com/blog/php-7-2-hosting-on-cloudways/ ) allows you to launch a PHP server on cloud in just one click and then upgrade your version to 7.2 from server management settings in one-click as well. The whole process takes under 20minutes.
can you write a tutorial about compiling php latest from source i tried but confusing
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
i get this error..after php7.2
php: symbol lookup error: php: undefined symbol: pcre_jit_exec
Which OS are you using? Are you using a 32bit system? Please try to update libpcre3 package on your system.
Thank you sir. this worked for me too 🙂
Thank you for updating php 7.2
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 ?
Nice post .Thanks for this awesome post.
Rahul, how I can fast switch between PHP 7.0 – 7.1 using PPA ?
Thanks Rahul. Very useful article.
Thank you for your effort, it saves a day 🙂
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.
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?
Yes Kevin,
I agree with you. I have informed the repository owner regarding it.
Thanks, Rahul,
I am a Web Developer and recently shifted to Ubuntu, i was searching for 3-5 hours to install PHP7. Glad to find your blog.
Harshal,
https://www.pitechnologies.org
You Are relay save my day Thanks for this Grate Tutorial
Thanks for saving my day 🙂
Thanks for this!
I had to also add python-software-properties-common in order to get add-apt-repository.
I’m on 15.10
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
Thanks for your information. We have updated article accordingly.
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.
Hi, how can I install phpMyAdmin with PHP7.0? Thank you.
Hi,
Download phpMyAdmin source code and extract on DocumentRoot. Currently I could not found any phpmyadmin packages which support php7
https://www.phpmyadmin.net/downloads/
Maybe you want to try single file database management called Adminer .. its so fast and light
https://www.adminer.org/