{"id":12906,"date":"2019-03-29T02:06:53","date_gmt":"2019-03-29T02:06:53","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12906"},"modified":"2019-03-29T02:06:53","modified_gmt":"2019-03-29T02:06:53","slug":"how-to-install-different-php-5-6-7-0-and-7-1-versions-in-ubuntu","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/29\/how-to-install-different-php-5-6-7-0-and-7-1-versions-in-ubuntu\/","title":{"rendered":"How to Install Different PHP (5.6, 7.0 and 7.1) Versions in Ubuntu"},"content":{"rendered":"<p><strong>PHP<\/strong>\u00a0(recursive acronym for\u00a0<strong>PHP: Hypertext Preprocessor<\/strong>) is an open source, popular general-purpose scripting language that is widely-used and best suited for developing websites and web-based applications. It is a server-side scripting language that can be embedded in HTML.<\/p>\n<p>Currently, there are three supported versions of\u00a0<strong>PHP<\/strong>, i.e\u00a0<strong>PHP 5.6<\/strong>,\u00a0<strong>7.0<\/strong>\u00a0and\u00a0<strong>7.1<\/strong>. Meaning\u00a0<strong>PHP 5.3<\/strong>,\u00a0<strong>5.4<\/strong>\u00a0and\u00a0<strong>5.5<\/strong>have all reached end of life; they are no longer supported with security updates.<\/p>\n<p>In this article, we will explain how to install all the supported versions of\u00a0<strong>PHP<\/strong>\u00a0in\u00a0<strong>Ubuntu<\/strong>\u00a0and its derivatives with most requested PHP extensions for both\u00a0<strong>Apache<\/strong>\u00a0and\u00a0<strong>Nginx<\/strong>\u00a0web servers using a\u00a0<strong>Ond\u0159ej Sur\u00fd PPA<\/strong>. We will also explain how to set default version of PHP to be used on the Ubuntu system.<\/p>\n<p>Note that\u00a0<strong>PHP 7.x<\/strong>\u00a0is the supported stable version in the Ubuntu software repositories, you can confirm this by running the\u00a0<a href=\"https:\/\/www.tecmint.com\/apt-advanced-package-command-examples-in-ubuntu\/\" target=\"_blank\" rel=\"noopener\">apt command<\/a>\u00a0below.<\/p>\n<pre>$sudo apt show php\r\nOR\r\n$ sudo apt show php -a\r\n<\/pre>\n<div class=\"code-label\">Show PHP Version Information<\/div>\n<pre>Package: php\r\nVersion: 1:7.0+35ubuntu6\r\nPriority: optional\r\nSection: php\r\nSource: php-defaults (35ubuntu6)\r\nOrigin: Ubuntu\r\nMaintainer: Ubuntu Developers &lt;ubuntu-devel-discuss@lists.ubuntu.com&gt;\r\nOriginal-Maintainer: Debian PHP Maintainers &lt;pkg-php-maint@lists.alioth.debian.org&gt;\r\nBugs: https:\/\/bugs.launchpad.net\/ubuntu\/+filebug\r\nInstalled-Size: 11.3 kB\r\nDepends: php7.0\r\nSupported: 5y\r\nDownload-Size: 2,832 B\r\nAPT-Sources: http:\/\/archive.ubuntu.com\/ubuntu xenial\/main amd64 Packages\r\nDescription: server-side, HTML-embedded scripting language (default)\r\n PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used\r\n open source general-purpose scripting language that is especially suited\r\n for web development and can be embedded into HTML.\r\n .\r\n This package is a dependency package, which depends on Debian's default\r\n PHP version (<strong>currently 7.0<\/strong>).<\/pre>\n<p>To install the default PHP version from the Ubuntu software repositories, use the command below.<\/p>\n<pre>$ sudo apt install php\r\n<\/pre>\n<h3>Install PHP (5.6, 7.0, 7.1) on Ubuntu Using PPA<\/h3>\n<p><strong>1.<\/strong>\u00a0First start by adding\u00a0<strong>Ond\u0159ej Sur\u00fd PPA<\/strong>\u00a0to install different versions of PHP \u2013\u00a0<strong>PHP 5.6<\/strong>,\u00a0<strong>PHP 7.0<\/strong>\u00a0and\u00a0<strong>PHP 7.1<\/strong>\u00a0on Ubuntu system.<\/p>\n<pre>$ sudo apt install python-software-properties\r\n$ sudo add-apt-repository ppa:ondrej\/php\r\n<\/pre>\n<div id=\"attachment_26247\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Add-PPA-in-Ubuntu.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-26247\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Add-PPA-in-Ubuntu.png\" sizes=\"auto, (max-width: 885px) 100vw, 885px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Add-PPA-in-Ubuntu.png 885w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Add-PPA-in-Ubuntu-768x613.png 768w\" alt=\"Add PPA in Ubuntu\" width=\"885\" height=\"706\" aria-describedby=\"caption-attachment-26247\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-26247\" class=\"wp-caption-text\">Add PPA in Ubuntu<\/p>\n<\/div>\n<p><strong>2.<\/strong>\u00a0Next, update the system as follows.<\/p>\n<pre>$ sudo apt-get update\r\n<\/pre>\n<p><strong>3.<\/strong>\u00a0Now install different supported versions of PHP as follows.<\/p>\n<h4>For Apache Web Server<\/h4>\n<pre>$ sudo apt install php5.6   [<strong>PHP 5.6<\/strong>]\r\n$ sudo apt install php7.0   [<strong>PHP 7.0<\/strong>]\r\n$ sudo apt install php7.1   [<strong>PHP 7.1<\/strong>]\r\n<\/pre>\n<h4>For Nginx Web Server<\/h4>\n<pre>$ sudo apt install php5.6-fpm   [<strong>PHP 5.6<\/strong>]\r\n$ sudo apt install php7.0-fpm   [<strong>PHP 7.0<\/strong>]\r\n$ sudo apt install php7.1-fpm   [<strong>PHP 7.1<\/strong>]\r\n<\/pre>\n<p><strong>4.<\/strong>\u00a0To install any PHP modules, simply specify the PHP version and use the auto-completion functionality to view all modules as follows.<\/p>\n<pre>------------ <strong>press Tab key for auto-completion<\/strong> ------------ \r\n$ sudo apt install php5.6 \r\n$ sudo apt install php7.0 \r\n$ sudo apt install php7.1 \r\n<\/pre>\n<div id=\"attachment_26257\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Search-PHP-Modules.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-26257\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Search-PHP-Modules.png\" alt=\"Search PHP Modules\" width=\"762\" height=\"266\" aria-describedby=\"caption-attachment-26257\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-26257\" class=\"wp-caption-text\">Search PHP Modules<\/p>\n<\/div>\n<p><strong>5.<\/strong>\u00a0Now you can install most required PHP modules from the list.<\/p>\n<pre>------------ <strong>Install PHP Modules<\/strong> ------------\r\n$ sudo apt install php5.6-cli php5.6-xml php5.6-mysql \r\n$ sudo apt install php7.0-cli php7.0-xml php7.0-mysql \r\n$ sudo apt install php7.1-cli php7.1-xml php7.1-mysql \r\n<\/pre>\n<p><strong>6.<\/strong>\u00a0Finally, verify your default PHP version used on your system like this.<\/p>\n<pre>$ php -v \r\n<\/pre>\n<div id=\"attachment_26248\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Check-Default-PHP-in-Ubuntu.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-26248\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Check-Default-PHP-in-Ubuntu.png\" sizes=\"auto, (max-width: 941px) 100vw, 941px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Check-Default-PHP-in-Ubuntu.png 941w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Check-Default-PHP-in-Ubuntu-768x127.png 768w\" alt=\"Check Default PHP Version in Ubuntu\" width=\"941\" height=\"156\" aria-describedby=\"caption-attachment-26248\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-26248\" class=\"wp-caption-text\">Check Default PHP Version in Ubuntu<\/p>\n<\/div>\n<h3>Set Default PHP Version in Ubuntu<\/h3>\n<p><strong>7.<\/strong>\u00a0You can set the default PHP version to be used on the system with the\u00a0<strong>update-alternatives<\/strong>\u00a0command, after setting it, check the PHP version to confirm as follows.<\/p>\n<pre>------------ <strong>Set Default PHP Version 5.6<\/strong> ------------\r\n$ sudo update-alternatives --set php \/usr\/bin\/php5.6\r\n<\/pre>\n<div id=\"attachment_26251\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Set-PHP-5.6-in-Ubuntu.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-26251\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Set-PHP-5.6-in-Ubuntu.png\" sizes=\"auto, (max-width: 803px) 100vw, 803px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Set-PHP-5.6-in-Ubuntu.png 803w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Set-PHP-5.6-in-Ubuntu-768x254.png 768w\" alt=\"Set PHP 5.6 Version in Ubuntu\" width=\"803\" height=\"266\" aria-describedby=\"caption-attachment-26251\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-26251\" class=\"wp-caption-text\">Set PHP 5.6 Version in Ubuntu<\/p>\n<\/div>\n<pre>------------ <strong>Set Default PHP Version 7.0<\/strong> ------------\r\n$ sudo update-alternatives --set php \/usr\/bin\/php7.0\r\n<\/pre>\n<div id=\"attachment_26252\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Set-PHP-7.0-in-Ubuntu.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-26252\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Set-PHP-7.0-in-Ubuntu.png\" sizes=\"auto, (max-width: 804px) 100vw, 804px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Set-PHP-7.0-in-Ubuntu.png 804w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Set-PHP-7.0-in-Ubuntu-768x233.png 768w\" alt=\"Set PHP 7.0 Version in Ubuntu\" width=\"804\" height=\"244\" aria-describedby=\"caption-attachment-26252\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-26252\" class=\"wp-caption-text\">Set PHP 7.0 Version in Ubuntu<\/p>\n<\/div>\n<pre>------------ <strong>Set Default PHP Version 7.1<\/strong> ------------\r\n$ sudo update-alternatives --set php \/usr\/bin\/php7.1\r\n<\/pre>\n<div id=\"attachment_26253\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Set-PHP-7.1-in-Ubuntu.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-26253\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Set-PHP-7.1-in-Ubuntu.png\" sizes=\"auto, (max-width: 806px) 100vw, 806px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Set-PHP-7.1-in-Ubuntu.png 806w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Set-PHP-7.1-in-Ubuntu-768x232.png 768w\" alt=\"Set PHP 7.1 Version in Ubuntu\" width=\"806\" height=\"244\" aria-describedby=\"caption-attachment-26253\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-26253\" class=\"wp-caption-text\">Set PHP 7.1 Version in Ubuntu<\/p>\n<\/div>\n<p><strong>8.<\/strong>\u00a0To set the PHP version that will work with\u00a0<strong>Apache<\/strong>\u00a0web server, use the commands below. First disable the current version with the\u00a0<strong>a2dismod<\/strong>\u00a0command and then enable the one you want with the\u00a0<strong>a2enmod<\/strong>\u00a0command.<\/p>\n<pre>$ sudo a2dismod php7.0\r\n$ sudo a2enmod php7.1\r\n$ sudo systemctl restart apache2\r\n<\/pre>\n<div id=\"attachment_26250\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Enable-Disable-PHP-Modules-for-Apache.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-26250\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Enable-Disable-PHP-Modules-for-Apache.png\" alt=\"Enable Disable PHP Modules for Apache\" width=\"623\" height=\"323\" aria-describedby=\"caption-attachment-26250\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-26250\" class=\"wp-caption-text\">Enable Disable PHP Modules for Apache<\/p>\n<\/div>\n<p><strong>9.<\/strong>\u00a0After switching from one version to another, you can find your PHP configuration file, by running the command below.<\/p>\n<pre>------------ <strong>For PHP 5.6<\/strong> ------------\r\n$ sudo update-alternatives --set php \/usr\/bin\/php5.6\r\n$ php -i | grep \"Loaded Configuration File\"\r\n\r\n------------ <strong>For PHP 7.0<\/strong> ------------\r\n$ sudo update-alternatives --set php \/usr\/bin\/php7.0\r\n$ php -i | grep \"Loaded Configuration File\"\r\n\r\n------------ <strong>For PHP 7,1<\/strong> ------------\r\n$ sudo update-alternatives --set php \/usr\/bin\/php7.1\r\n$ php -i | grep \"Loaded Configuration File\"\r\n<\/pre>\n<div id=\"attachment_26249\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Find-PHP-Configuration-File.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-26249\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Find-PHP-Configuration-File.png\" sizes=\"auto, (max-width: 804px) 100vw, 804px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Find-PHP-Configuration-File.png 804w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/07\/Find-PHP-Configuration-File-768x401.png 768w\" alt=\"Find PHP Configuration File\" width=\"804\" height=\"420\" aria-describedby=\"caption-attachment-26249\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-26249\" class=\"wp-caption-text\">Find PHP Configuration File<\/p>\n<\/div>\n<p>You may also like:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/run-php-codes-from-linux-commandline\/\" target=\"_blank\" rel=\"noopener\">How to Use and Execute PHP Codes in Linux Command Line<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/execute-php-codes-functions-in-linux-commandline\/\" target=\"_blank\" rel=\"noopener\">12 Useful PHP Commandline Usage Every Linux User Must Know<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/hide-php-version-http-header\/\" target=\"_blank\" rel=\"noopener\">How to Hide PHP Version in HTTP Header<\/a><\/li>\n<\/ol>\n<p>In this article, we showed how to install all the supported versions of PHP in Ubuntu and its derivatives. If you have any queries or thoughts to share, do so via the feedback form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/install-different-php-versions-in-ubuntu\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u00a0(recursive acronym for\u00a0PHP: Hypertext Preprocessor) is an open source, popular general-purpose scripting language that is widely-used and best suited for developing websites and web-based applications. It is a server-side scripting language that can be embedded in HTML. Currently, there are three supported versions of\u00a0PHP, i.e\u00a0PHP 5.6,\u00a07.0\u00a0and\u00a07.1. Meaning\u00a0PHP 5.3,\u00a05.4\u00a0and\u00a05.5have all reached end of life; they are &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/29\/how-to-install-different-php-5-6-7-0-and-7-1-versions-in-ubuntu\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Install Different PHP (5.6, 7.0 and 7.1) Versions in Ubuntu&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12906","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12906","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12906"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12906\/revisions"}],"predecessor-version":[{"id":12907,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12906\/revisions\/12907"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}