A thorough solution to the installation and version switching of PHP on Ubuntu

Source: Internet
Author: User
Tags config php gmp xsl

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.

  1. 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
  2. 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
  3. 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
  4. Switch PHP version

    sudo update-alternatives --config php
  5. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.