CentOS 6
Sponsored Link

Install PHP 5.62016/07/28

 
The version of PHP in CentOS 6 repository is 5.3 but Install 5.6 with RPM package if you need.
[1] It's possible to install from CentOS SCLo Software Collections.
It's OK to install it even if 5.3 is already installed because 5.6 is located on another PATH.
# install from SCLo

[root@dlp ~]#
yum --enablerepo=centos-sclo-rh -y install rh-php56
[2] Packages from Software Collections are installed uder the /opt directory.
To use it, Load environment variables like follows.
# load environment variables

[root@dlp ~]#
scl enable rh-php56 bash
[root@dlp ~]#
php -v

PHP 5.6.5 (cli) (built: Mar 23 2016 19:16:57)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
[root@dlp ~]#
which php

/opt/rh/rh-php56/root/usr/bin/php
[3] If you'd like to enable PHP 5.6 automatically at login time, configure like follows.
[root@dlp ~]#
vi /etc/profile.d/rh-php56.sh
# create new

#!/bin/bash

source /opt/rh/rh-php56/enable
export X_SCLS="`scl enable rh-php56 'echo $X_SCLS'`"
[4] This is an example to use 5.6 with Apache httpd. Configure it with Apache httpd 2.4 provided from SCLo on here.
# install from SCLo

[root@dlp ~]#
yum --enablerepo=centos-sclo-rh -y install rh-php56-php httpd24
[root@dlp ~]#
/etc/rc.d/init.d/httpd stop

[root@dlp ~]#
/etc/rc.d/init.d/httpd24-httpd start

Starting httpd: [ OK ]
# create phpinfo under the document-root to verify working

[root@dlp ~]#
echo '<?php phpinfo(); ?>' > /opt/rh/httpd24/root/var/www/html/info.php

[root@dlp ~]#
curl http://localhost/info.php | grep 'PHP Version' | tail -1 | sed -e 's/<[^>]*>//g'

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 68819    0 68819    0     0  5529k      0 --:--:-- --:--:-- --:--:-- 6109k
PHP Version 5.6.5
[5] For the case with Apache httpd 2.4 + PHP-FPM, Configure like follows.
# install from SCLo

[root@dlp ~]#
yum --enablerepo=centos-sclo-rh -y install rh-php56-php-fpm
[root@dlp ~]#
vi /opt/rh/httpd24/root/etc/httpd/conf.d/rh-php56-php.conf
# line 31: change like follows

<FilesMatch \.php$>
#
    SetHandler application/x-httpd-php
    SetHandler "proxy:fcgi://127.0.0.1:9000"

</FilesMatch>
[root@dlp ~]#
/etc/rc.d/init.d/rh-php56-php-fpm start

[root@dlp ~]#
/etc/rc.d/init.d/httpd24-httpd restart

Matched Content