The official source of Ubuntu, such as the Ubuntu14.04 default source is the php5.6.x, Ubuntu16.04 default source is php7.0.x, then if you want to install Ubuntu16.04 on php7.1,php7.2, what should I do?
The answer is to install from a third-party source, ppa:ondrej/php is a well-known PHP source (currently maintaining php5.6,php7.0,php7.1,php7.2). Use this source to install the PHP version you want.
Installing PHP from the source
sudo add-apt-repository ppa:ondrej/phpsudo apt-get updatesudo apt-get upgradesudo apt-get install php7.1 # for PHP 7.1sudo apt-get install php7.0 # for PHP 7.0sudo apt-get install php5.6 # for PHP 5.6
Install the relevant version of the PHP module
sudoApt-cache Search php7*...Php-all-dev-Package depending on all supported PHP development packagesphp7.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 languagePhp7.0-common-documentation, examples and common module for PHPPhp7.0-curl-CURL Module for PHPPhp7.0-dev-Files for PHP7.0 module developmentPHP7.0-GD-GD Module for PHPPhp7.0-gmp-GMP Module for PHP.........Php7.1-xml-DOM, SimpleXML, WDDX, XML, and XSL module for PHPPhp7.1-xmlrpc-Xmlrpc-epi Module for PHPPhp7.1-zip-Zip Module for PHPPhp7.1-opcache-Zend Opcache Module for PHPphp7.1-Server-side, html-embedded scripting language (metapackage)php7.1-xsl-XSL module for PHP (dummy)......Php7.2-bcmath-Bcmath Module for PHPphp7.2-bz2-BZIP2 Module for PHPphp7.2-cgi-Server-side, html-embedded scripting language (CGI binary)php7.2-cli-Command-Line interpreter for the PHP scripting languagePhp7.2-common-documentation, examples and common module for PHPPhp7.2-curl-CURL Module for PHPPHP7.2-DBA-DBA Module for PHP
Select the required modules, install the
sudo apt-get install php7.2-curl php7.2-dev php7.2-gd php7.2-imap php7.2-intl php7.2-mbstring php7.2-mysql php7.2-xml php7.2-zip
Switch PHP version
sudo update-alternatives --config php
Set Apache to run with the correct PHP version
sudo a2dismod php7.1 # unload the current versionsudo a2enmod php5.6 # load the version you needsudo# restart webserver to apply
At the end of this, there is no need to worry about installing PHP, switching PHP versions of these things.
Reference:
- https://askubuntu.com/questions/109404/how-do-i-install-different-upgrade-or-downgrade-php-version-in-still-supported
- https://tecadmin.net/install-php-7-on-ubuntu/
A thorough solution to the installation and version switching of PHP on Ubuntu