PHP 7.2 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 the specific version of PHP, then this article can be helpful for you. This article will help you to install PHP 7.2, 7.1 & PHP 7.0 on Ubuntu 17.10, 16.04 & 14.04 using PPA
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 python-software-properties 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.0-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Nov 30 2017 13:58:33) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.2.0-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, 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 it.
sudo apt-get install python-software-properties 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.12-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Nov 29 2017 10:03:25) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.1.12-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, 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 it.
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.26-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Nov 29 2017 09:51:01) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.26-1+ubuntu16.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 find our available PHP 7 modules.
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 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.

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 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/