This article completely solves the installation and version switch of PHP on Ubuntu

Source: Internet
Author: User
Tags config php gmp

This article completely solves the installation and version switch of PHP on Ubuntu

Official sources on Ubuntu. For example, PHP5.6.x and Ubuntu16.04 are the default sources PHP7.0.x. What should I do if I want to install PHP7.1 and PHP7.2 on Ubuntu16.04?

The answer is to install it through a third-party source. ppa: ondrej/php is a well-known PHP source (currently maintaining php5.6, php7.0, php7.1, php7.2 ). Next we will use this source to install the desired PHP version.

1. install PHP from the source

Sudo add-apt-repository ppa: ondrej/php
Sudo apt-get update
Sudo apt-get upgrade
Sudo apt-get install php7.1 # for PHP 7.1
Sudo apt-get install php7.0 # for PHP 7.0
Sudo apt-get install php5.6 # for PHP 5.6

2. Install the PHP module of the relevant version.

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 module for PHP

3. Select the required module and install it.

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 to the PHP version.

Sudo update-alternatives -- config php

5. Set Apache to run with the correct PHP version.

Sudo a2dismod php7.1 # unload the current version
Sudo a2enmod php5.6 # load the version you need
Sudo service apache2 restart # restart webserver to apply

By now, you no longer have to worry about installing PHP and switch to the PHP version.

Refer:

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

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151601.htm

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.