Install Different PHP (5.6, 7.0 and 7.1) Versions in Ubuntu

Which PHP

Which Ubuntu

Main PPA for PHP

https://launchpad.net/~ondrej/+archive/ubuntu/php/

PHP 버전 확인

$ sudo apt show php (아니면 sudo apt show php -a)
Package: php
Version: 1:7.0+49
Priority: optional
Section: php
Source: php-defaults (49)
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 12.3 kB
Depends: php7.0
Supported: 9m
Download-Size: 2,860 B
APT-Sources: http://kr.archive.ubuntu.com/ubuntu zesty/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
 PHP (PHP 의미는 PHP: Hypertext Preprocessor 로 재귀 약자입니다) 는 특히 웹 개발에 적합하고 HTML에
 삽입 할 수 있는, 널리 사용되는 오픈 소스 범용 스크립 트 언어입니다.
 .
 This package is a dependency package, which depends on Debian's default
 PHP version (currently 7.0).

PPA 설치 준비

$ sudo apt install python-software-properties
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다       
상태 정보를 읽는 중입니다... 완료
The following additional packages will be installed:
  python-apt python-pycurl
제안하는 패키지:
  python-apt-dbg python-apt-doc libcurl4-gnutls-dev python-pycurl-dbg python-pycurl-doc
다음 새 패키지를 설치할 것입니다:
  python-apt python-pycurl python-software-properties
0개 업그레이드, 3개 새로 설치, 0개 제거 및 0개 업그레이드 안 함.
208 k바이트 아카이브를 받아야 합니다.
이 작업 후 952 k바이트의 디스크 공간을 더 사용하게 됩니다.
계속 하시겠습니까? [Y/n] y
받기:1 http://kr.archive.ubuntu.com/ubuntu zesty/main amd64 python-apt amd64 1.4.0~beta2 [143 kB]
받기:2 http://kr.archive.ubuntu.com/ubuntu zesty/main amd64 python-pycurl amd64 7.43.0-2 [44.0 kB]
받기:3 http://kr.archive.ubuntu.com/ubuntu zesty/universe amd64 python-software-properties all 0.96.24.13 [20.8 kB]
내려받기 208 k바이트, 소요시간 0초 (355 k바이트/초)
Selecting previously unselected package python-apt.
(데이터베이스 읽는중 ...현재 208588개의 파일과 디렉터리가 설치되어 있습니다.)
Preparing to unpack .../python-apt_1.4.0~beta2_amd64.deb ...
Unpacking python-apt (1.4.0~beta2) ...
Selecting previously unselected package python-pycurl.
Preparing to unpack .../python-pycurl_7.43.0-2_amd64.deb ...
Unpacking python-pycurl (7.43.0-2) ...
Selecting previously unselected package python-software-properties.
Preparing to unpack .../python-software-properties_0.96.24.13_all.deb ...
Unpacking python-software-properties (0.96.24.13) ...
python-pycurl (7.43.0-2) 설정하는 중입니다 ...
python-apt (1.4.0~beta2) 설정하는 중입니다 ...
python-software-properties (0.96.24.13) 설정하는 중입니다 ...

PPA 설치

$ sudo add-apt-repository ppa:ondrej/php 
 Co-installable PHP versions: PHP 5.6, PHP 7.0, PHP 7.1 and most requested extensions are included.

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.

You can get more information about the packages at https://deb.sury.org

BUGS&FEATURES: This PPA now has a issue tracker: https://deb.sury.org/#bug-reporting

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/

WARNING: add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:

# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
 더 많은 정보: https://launchpad.net/~ondrej/+archive/ubuntu/php
계속하려면 [엔터] 키를 누르시고 추가를 취소하려면 컨트롤+C 키를 눌러주십시오

gpg: keybox '/tmp/tmp3osq6n84/pubring.gpg' created
gpg: /tmp/tmp3osq6n84/trustdb.gpg: trustdb created
gpg: key 4F4EA0AAE5267A6C: public key "Launchpad PPA for Ondřej Surý" imported
gpg: Total number processed: 1
gpg:               imported: 1
OK

repository 최신화

$ sudo apt-get update
기존:1 http://kr.archive.ubuntu.com/ubuntu zesty InRelease
기존:2 http://kr.archive.ubuntu.com/ubuntu zesty-updates InRelease                                                      
기존:3 http://kr.archive.ubuntu.com/ubuntu zesty-backports InRelease                                                    
기존:4 http://security.ubuntu.com/ubuntu zesty-security InRelease                                                       
기존:5 http://ppa.launchpad.net/ondrej/php/ubuntu zesty InRelease                                      
패키지 목록을 읽는 중입니다... 완료

설치가능 PHP 확인 (default)

$ sudo apt show php
Package: php
Version: 1:7.1+53~ubuntu17.04.1+deb.sury.org+1
Priority: optional
Section: php
Source: php-defaults (53~ubuntu17.04.1+deb.sury.org+1)
Maintainer: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>
Installed-Size: 12.3 kB
Depends: php7.1
Download-Size: 5,280 B
APT-Sources: http://ppa.launchpad.net/ondrej/php/ubuntu zesty/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
 PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
 open source general-purpose scripting language that is especially suited
 for web development and can be embedded into HTML.
 .
 This package is a dependency package, which depends on latest stable
 PHP version (currently 7.1).

N: There is 1 additional record. Please use the '-a' switch to see it

설치가능 PHP 확인 (5.6)

$ sudo apt show php5.6
Package: php5.6
Version: 5.6.31-2+ubuntu17.04.1+deb.sury.org+1
Priority: optional
Section: php
Maintainer: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>
Installed-Size: 286 kB
Provides: php
Depends: libapache2-mod-php5.6 | php5.6-fpm | php5.6-cgi, php5.6-common
Download-Size: 260 kB
APT-Sources: http://ppa.launchpad.net/ondrej/php/ubuntu zesty/main amd64 Packages
Description: server-side, HTML-embedded scripting language (metapackage)
 This package is a metapackage that, when installed, guarantees that you
 have at least one of the four server-side versions of the PHP interpreter
 installed. Removing this package won't remove PHP from your system, however
 it may remove other packages that depend on this one.
 .
 PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
 open source general-purpose scripting language that is especially suited
 for web development and can be embedded into HTML.

설치가능 PHP 확인 (7.0)

$ sudo apt show php7.0
Package: php7.0
Version: 7.0.21-1~ubuntu17.04.1+deb.sury.org+1
Priority: optional
Section: php
Maintainer: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>
Installed-Size: 76.8 kB
Provides: php
Depends: libapache2-mod-php7.0 | php7.0-fpm | php7.0-cgi, php7.0-common
Download-Size: 50.1 kB
APT-Sources: http://ppa.launchpad.net/ondrej/php/ubuntu zesty/main amd64 Packages
Description: 서버사이드, HTML 내장 스크립팅 언어 (메타패키지)
 This package is a metapackage that, when installed, guarantees that you
 have at least one of the four server-side versions of the PHP interpreter
 installed. Removing this package won't remove PHP from your system,
 however it may remove other packages that depend on this one.
 .
 PHP (PHP 의미는 PHP: Hypertext Preprocessor 로 재귀 약자입니다) 는 특히 웹 개발에 적합하고 HTML에
 삽입 할 수 있는, 널리 사용되는 오픈 소스 범용 스크립 트 언어입니다.

N: There are 2 additional records. Please use the '-a' switch to see them.

PHP PPA가 설치되지 않았으면

$ sudo apt show php5.6
Package: php5.6-common
State: not a real package (virtual)
Package: php5.6-json
State: not a real package (virtual)
N: 패키지가 없습니다

$ sudo apt show php7.1
N: php7.1 패키지를 찾을 수 없습니다
N: Couldn't find any package by glob 'php7.1'
N: 'php7.1' 정규식에 해당하는 패키지가 없습니다
N: php7.1 패키지를 찾을 수 없습니다
N: Couldn't find any package by glob 'php7.1'
N: 'php7.1' 정규식에 해당하는 패키지가 없습니다
E: 패키지가 없습니다

$ sudo apt show php7.0
Package: php7.0
Version: 7.0.18-0ubuntu0.17.04.1
Priority: optional
Section: php
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 76.8 kB
Provides: php
Depends: libapache2-mod-php7.0 | php7.0-fpm | php7.0-cgi, php7.0-common
Homepage: http://www.php.net/
Supported: 9m
Download-Size: 5,598 B
APT-Sources: http://kr.archive.ubuntu.com/ubuntu zesty-updates/main amd64 Packages
Description: 서버사이드, HTML 내장 스크립팅 언어 (메타패키지)
 This package is a metapackage that, when installed, guarantees that you
 have at least one of the four server-side versions of the PHP interpreter
 installed. Removing this package won't remove PHP from your system,
 however it may remove other packages that depend on this one.
 .
 PHP (PHP 의미는 PHP: Hypertext Preprocessor 로 재귀 약자입니다) 는 특히 웹 개발에 적합하고 HTML에
 삽입 할 수 있는, 널리 사용되는 오픈 소스 범용 스크립 트 언어입니다.

N: There is 1 additional record. Please use the '-a' switch to see it

PHP Module 추가설치

$ sudo apt install php7.1 (Apache Web Server)
php7.1            php7.1-dba        php7.1-interbase  php7.1-odbc       php7.1-snmp       php7.1-xsl
php7.1-bcmath     php7.1-dev        php7.1-intl       php7.1-opcache    php7.1-soap       php7.1-zip
php7.1-bz2        php7.1-enchant    php7.1-json       php7.1-pgsql      php7.1-sqlite3    
php7.1-cgi        php7.1-fpm        php7.1-ldap       php7.1-phpdbg     php7.1-sybase     
php7.1-cli        php7.1-gd         php7.1-mbstring   php7.1-pspell     php7.1-tidy       
php7.1-common     php7.1-gmp        php7.1-mcrypt     php7.1-readline   php7.1-xml        
php7.1-curl       php7.1-imap       php7.1-mysql      php7.1-recode     php7.1-xmlrpc     

$ sudo apt install php7.1-fpm (Nginx Web Server)
Display all 57779 possibilities? (y or n)
0ad
0ad-data
0ad-data-common
0install
0install-core
0xffff
2048-qt
2ping
2vcard
3270-common
389-admin
389-admin-console
389-console
389-ds
389-ds-base
389-ds-base-dev
389-ds-base-libs
389-ds-console
389-ds-console-doc
389-dsgw
3dchess
3depict
3dldf
3dldf-doc
3dldf-doc-examples
4digits

Set Default PHP Version

$ sudo update-alternatives --set php /usr/bin/php
php     php5.6  php7.0  php7.1  

$ php -v
PHP 7.1.7-1+ubuntu17.04.1+deb.sury.org+1 (cli) (built: Jul  7 2017 09:43:21) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.7-1+ubuntu17.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies

$ sudo update-alternatives --set php /usr/bin/php5.6
update-alternatives: using /usr/bin/php5.6 to provide /usr/bin/php (php) in manual mode

$ php -v
PHP 5.6.31-2+ubuntu17.04.1+deb.sury.org+1 (cli) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

$ sudo update-alternatives --set php /usr/bin/php7.0
update-alternatives: using /usr/bin/php7.0 to provide /usr/bin/php (php) in manual mode

$ php -v
PHP 7.0.21-1~ubuntu17.04.1+deb.sury.org+1 (cli) (built: Jul  6 2017 09:11:36) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.21-1~ubuntu17.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies

$ sudo update-alternatives --set php /usr/bin/php7.1
update-alternatives: using /usr/bin/php7.1 to provide /usr/bin/php (php) in manual mode

$ php -v
PHP 7.1.7-1+ubuntu17.04.1+deb.sury.org+1 (cli) (built: Jul  7 2017 09:43:21) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.7-1+ubuntu17.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies

Set Apache PHP Version

$ sudo a2dismod php7.0
Module php7.0 already disabled

$ sudo a2dismod php5.6
Module php5.6 already disabled

$ sudo a2dismod php7.1
Module php7.1 disabled.
To activate the new configuration, you need to run:
  systemctl restart apache2

$ sudo a2enmod php7.1
Considering dependency mpm_prefork for php7.1:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php7.1:
Enabling module php7.1.
To activate the new configuration, you need to run:
  systemctl restart apache2

$ sudo systemctl restart apache2

Find PHP Conguration File

$ php -v
PHP 7.1.7-1+ubuntu17.04.1+deb.sury.org+1 (cli) (built: Jul  7 2017 09:43:21) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.7-1+ubuntu17.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies

$ php -i | grep "Loaded Configuration File"
Loaded Configuration File => /etc/php/7.1/cli/php.ini

$ sudo update-alternatives --set php /usr/bin/php5.6
update-alternatives: using /usr/bin/php5.6 to provide /usr/bin/php (php) in manual mode

$ php -i | grep "Loaded Configuration File"
Loaded Configuration File => /etc/php/5.6/cli/php.ini

$ sudo update-alternatives --set php /usr/bin/php7.0
update-alternatives: using /usr/bin/php7.0 to provide /usr/bin/php (php) in manual mode

$ php -i | grep "Loaded Configuration File"         
Loaded Configuration File => /etc/php/7.0/cli/php.ini

감사합니다!

9월에는 CentOS에서 해보겠습니다!

 

http://slides.com/fermat39/install-different-php-5-6-7-0-and-7-1-versions-in-ubuntu

Install Different PHP (5.6, 7.0 and 7.1) Versions in Ubuntu

By fermat39

Install Different PHP (5.6, 7.0 and 7.1) Versions in Ubuntu

  • 1,819