How to install Multiple PHP versions on CentOS 6
To install Multiple PHP versions on CentOS 6
PHP is a server scripting language used for the development of software applications with the help of internet. It is a powerful tool to create dynamic contents for interaction with databases.In this tutorial we will be briefed on how to install and run two different PHP versions on same machine. For example both PHP versions 5 and 7 will be run on a single server because some of the applications may require for PHP version 5 and other applications may require for PHP version 7. So in this case we need to both PHP versions running in a single system.
Installation procedure
PHP version 5
To proceed with the installation procedure, install the PHP version 5 in the target system using yum install command and press y to continue with the installation.
[root@linuxhelp ~]# yum install php -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Determining fastest mirrors
* base: centos.mirror.snu.edu.in
* extras: centos.mirror.snu.edu.in
* updates: centos.mirror.snu.edu.in
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.3.3-49.el6 will be installed
--> Processing Dependency: php-common(x86-64) = 5.3.3-49.el6 for package: php-5.3.3-49.el6.x86_64
--> Processing Dependency: php-cli(x86-64) = 5.3.3-49.el6 for package: php-5.3.3-49.el6.x86_64
--> Running transaction check
---> Package php-cli.x86_64 0:5.3.3-49.el6 will be installed
.
.
.
Installed:
php.x86_64 0:5.3.3-49.el6
Dependency Installed:
php-cli.x86_64 0:5.3.3-49.el6 php-common.x86_64 0:5.3.3-49.el6
Complete!
The PHP is now installed successfully. To check the version of the PHP, run the following command.
[root@linuxhelp ~]# php -v
PHP 5.3.3 (cli) (built: Mar 22 2017 12:27:09)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
PHP version 7
Next install the second instance of PHP version 7 by compiling from it' s source code by executing the following command and press y to continue with the installation procedure
[root@linuxhelp ~]# yum groupinstall " Development Tools" -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
* base: centos.mirror.snu.edu.in
* extras: centos.mirror.snu.edu.in
* updates: centos.mirror.snu.edu.in
Package 1:make-3.81-23.el6.x86_64 already installed and latest version
Package patch-2.6-6.el6.x86_64 already installed and latest version
Package 1:pkgconfig-0.23-9.1.el6.x86_64 already installed and latest version
Package gettext-0.17-18.el6.x86_64 already installed and latest version
Package elfutils-0.164-2.el6.x86_64 already installed and latest version
Package cvs-1.11.23-16.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.63-5.1.el6 will be installed
---> Package automake.noarch 0:1.11.1-4.el6 will be installed
---> Package binutils.x86_64 0:2.20.51.0.2-5.46.el6 will be updated
---> Package binutils.x86_64 0:2.20.51.0.2-5.47.el6_9.1 will be an update
---> Package bison.x86_64 0:2.4.1-5.el6 will be installed
---> Package byacc.x86_64 0:1.9.20070509-7.el6 will be installed
---> Package cscope.x86_64 0:15.6-7.el6 will be installed
.
.
.
Dependency Installed:
cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.7-18.el6 gettext-devel.x86_64 0:0.17-18.el6 gettext-libs.x86_64 0:0.17-18.el6
kernel-devel.x86_64 0:2.6.32-696.13.2.el6 libgcj.x86_64 0:4.4.7-18.el6 libgfortran.x86_64 0:4.4.7-18.el6 libstdc++-devel.x86_64 0:4.4.7-18.el6
mpfr.x86_64 0:2.4.1-6.el6 perl-Compress-Raw-Zlib.x86_64 1:2.021-144.el6 perl-Compress-Zlib.x86_64 0:2.021-144.el6 perl-Error.noarch 1:0.17015-4.el6
perl-Git.noarch 0:1.7.1-9.el6_9 perl-HTML-Parser.x86_64 0:3.64-2.el6 perl-HTML-Tagset.noarch 0:3.20-4.el6 perl-IO-Compress-Base.x86_64 0:2.021-144.el6
perl-IO-Compress-Zlib.x86_64 0:2.021-144.el6 perl-URI.noarch 0:1.40-2.el6 perl-XML-Parser.x86_64 0:2.36-7.el6 perl-libwww-perl.noarch 0:5.833-5.el6
ppl.x86_64 0:0.10.2-11.el6 systemtap-client.x86_64 0:2.9-7.el6 systemtap-devel.x86_64 0:2.9-7.el6
Updated:
binutils.x86_64 0:2.20.51.0.2-5.47.el6_9.1
Complete!
Also install some of its required packages for source code compilation and run the following command.
[root@linuxhelp ~]# yum install libxml2-devel -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: centos.mirror.snu.edu.in
* extras: centos.mirror.snu.edu.in
* updates: centos.mirror.snu.edu.in
Resolving Dependencies
--> Running transaction check
---> Package libxml2-devel.x86_64 0:2.7.6-21.el6_8.1 will be installed
--> Processing Dependency: zlib-devel for package: libxml2-devel-2.7.6-21.el6_8.1.x86_64
--> Running transaction check
---> Package zlib-devel.x86_64 0:1.2.3-29.el6 will be installed
--> Finished Dependency Resolution
.
.
.
Installed:
libxml2-devel.x86_64 0:2.7.6-21.el6_8.1
Dependency Installed:
zlib-devel.x86_64 0:1.2.3-29.el6
Complete!
Now download the PHP source code from the URL http://php.net/releases/ and choose any version you want to install or simply use below wget command to install version 7.1.9 followed by the download link.
[root@linuxhelp ~]# wget http://in1.php.net/distributions/php-7.1.9.tar.gz
--2017-10-25 02:26:14-- http://in1.php.net/distributions/php-7.1.9.tar.gz
Resolving in1.php.net... 103.21.58.218
Connecting to in1.php.net|103.21.58.218|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19428408 (19M) [application/x-gzip]
Saving to: “ php-7.1.9.tar.gz”
100%[========================================================================================================================================================================> ] 19,428,408 1023K/s in 18s
2017-10-25 02:26:33 (1.04 MB/s) - “ php-7.1.9.tar.gz” saved [19428408/19428408]
Now extract the package using tar command.
[root@linuxhelp ~]# tar -xzf php-7.1.9.tar.gz
Move to newly extracted directory to compile PHP source code and run configure script to configure the PHP before installation process.
[root@linuxhelp ~]# cd php-7.1.9
[root@linuxhelp php-7.1.9]# ./configure --prefix=/usr/local/php2
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
.
.
.
config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
Run the make command to install all the files in your current directory path
[root@linuxhelp php-7.1.9]# make
/bin/sh /root/php-7.1.9/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/ -I/root/php-7.1.9/ext/opcache/ -DPHP_ATOM_INC -I/root/php-7.1.9/include -I/root/php-7.1.9/main -I/root/php-7.1.9 -I/root/php-7.1.9/ext/date/lib -I/usr/include/libxml2 -I/root/php-7.1.9/ext/sqlite3/libsqlite -I/root/php-7.1.9/TSRM -I/root/php-7.1.9/Zend -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS -c /root/php-7.1.9/ext/opcache/ZendAccelerator.c -o ext/opcache/ZendAccelerator.lo
/bin/sh /root/php-7.1.9/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/ -I/root/php-7.1.9/ext/opcache/ -DPHP_ATOM_INC -I/root/php-7.1.9/include -I/root/php-7.1.9/main -I/root/php-7.1.9 -I/root/php-7.1.9/ext/date/lib -I/usr/include/libxml2 -I/root/php-7.1.9/ext/sqlite3/libsqlite -I/root/php-7.1.9/TSRM -I/root/php-7.1.9/Zend -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS -c /root/php-7.1.9/ext/opcache/zend_accelerator_blacklist.c -o ext/opcache/zend_accelerator_blacklist.lo
/bin/sh /root/php-7.1.9/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/ -I/root/php-7.1.9/ext/opcache/ -DPHP_ATOM_INC -I/root/php-7.1.9/include -I/root/php-7.1.9/main -I/root/php-7.1.9 -I/root/php-7.1.9/ext/date/lib -I/usr/include/libxml2 -I/root/php-7.1.9/ext/sqlite3/libsqlite -I/root/php-7.1.9/TSRM -I/root/php-7.1.9/Zend -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS -c /root/php-7.1.9/ext/opcache/zend_accelerator_debug.c -o ext/opcache/zend_accelerator_debug.lo
.
.
.
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP' s phar extension be enabled.
clicommand.inc
directorytreeiterator.inc
invertedregexiterator.inc
pharcommand.inc
directorygraphiterator.inc
phar.inc
Build complete.
Next run the make install command to install all the files in /usr/local/php2 location, mentioned while running configure script.
[root@linuxhelp php-7.1.9]# make install
Installing shared extensions: /usr/local/php2/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary: /usr/local/php2/bin/
Installing PHP CLI man page: /usr/local/php2/php/man/man1/
Installing phpdbg binary: /usr/local/php2/bin/
Installing phpdbg man page: /usr/local/php2/php/man/man1/
Installing PHP CGI binary: /usr/local/php2/bin/
Installing PHP CGI man page: /usr/local/php2/php/man/man1/
Installing build environment: /usr/local/php2/lib/php/build/
Installing header files: /usr/local/php2/include/php/
Installing helper programs: /usr/local/php2/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php2/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php2/lib/php/
[PEAR] Archive_Tar - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.2
[PEAR] PEAR - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php2/etc/pear.conf
You may want to add: /usr/local/php2/lib/php to your php.ini include_path
/root/php-7.1.9/build/shtool install -c ext/phar/phar.phar /usr/local/php2/bin
ln -s -f phar.phar /usr/local/php2/bin/phar
Installing PDO headers: /usr/local/php2/include/php/ext/pdo/
Now move to installed php directory and find php file inside bin directory by listing the files in the specified directory.
[root@linuxhelp php-7.1.9]# cd /usr/local/php2/ [root@linuxhelp php2]# ls bin etc include lib php var [root@linuxhelp php2]# cd bin/ [root@linuxhelp bin]# ll total 90772 -rwxr-xr-x 1 root root 842 Oct 25 02:39 pear -rwxr-xr-x 1 root root 863 Oct 25 02:39 peardev -rwxr-xr-x 1 root root 779 Oct 25 02:39 pecl lrwxrwxrwx 1 root root 9 Oct 25 02:39 phar -> phar.phar -rwxr-xr-x 1 root root 53495 Oct 25 02:39 phar.phar -rwxr-xr-x 1 root root 30709380 Oct 25 02:39 php -rwxr-xr-x 1 root root 30530342 Oct 25 02:39 php-cgi -rwxr-xr-x 1 root root 2239 Oct 25 02:39 php-config -rwxr-xr-x 1 root root 31624172 Oct 25 02:39 phpdbg -rwxr-xr-x 1 root root 4562 Oct 25 02:39 phpize
Rename the file php into php2 because we have already installed previous PHP using yum command as mentioned above. To avoid any conflict, rename the file to php2.
[root@linuxhelp bin]# mv php php2
To create new command, first create a script file under /etc/profile.d/ directory location named php2.sh and enter the following content in the file. Save and exit the file.
[root@linuxhelp bin]# vim /etc/profile.d/php2.sh
pathmunge /usr/local/php2/bin/
Now close the current terminal and reopen a new terminal. Check the new command php2 is working by running the version of the php2. The second PHP is working without any clashes with the first PHP version.
[root@linuxhelp ~]# php2 -v
PHP 7.1.9 (cli) (built: Oct 25 2017 02:37:04) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
This concludes the installation procedure of multiple PHP on CentOS 6.
Comments ( 8 )
any idea please ?
any idea please ?
thanks you very much