VPS Linux Guides - CentOS

Upgrading Apache 2.2 to 2.4 and PHP 5.3 to 5.4 on CentOS 6

Installing the Software Collections Repo

                            yum update
                            yum install centos-release-SCL
                            yum update
                        

Updating PHP 5.3.3 to 5.4

                            yum search php54
                            yum install php54 
                            php -v
                            scl enable php54 "php -v"
                        

Configuring PHP 5.4 with Apache 2.2.15

Install the PHP 5.4 mod compiled for Apache 2.2.15 and disable PHP 5.3

                            yum install php54-php php54-*
                            source /opt/rh/php54/enable
                        

Remove / disable the old php 5.3 apache config

                            mv /etc/httpd/conf.d/php.conf /root/php.conf
                            mv /etc/httpd/modules/libphp5.so /root/libphp5.so
                        

Check the /etc/httpd/conf.d/php54-php.conf exists and is configured correctly

                            service httpd restart
                        

Load a phpinfo page to check the version of php being used by apache is now PHP 5.4

                            <?php
                            phpinfo();
                            ?>
                        

Configure PHP 5.4 with cli/bash

Add to all user’s ~/.bash_profile the following lines:

                            ## SCL Enabled Libraries
                            source /opt/rh/php54/enable
                        

This will enable PHP 5.4 on the command line for those users. Also when using Switch User (su) remember to run as logged in shell

                        sudo su -l root
                        

Omitting the -l flag will give a non-logged in shell and .bash_profile will NOT be run (in this case you could use ~/.bashrc).

Updating Apache 2.2 to 2.4.6

Warning this will stop PHP 5.4 working as an apache module, read PHP-FPM section before updating.

                            yum search httpd
                            yum install httpd24
                            yum install httpd24-*
                            yum install php54-php-fpm
                        

As the SCL PHP 5.4 mod_php has been compiled for Apache 2.2, the Apache ProxyCGI will need to be used along with PHP-FPM running as a service. See the next section for using PHP with Apache 2.4.

Add to all user’s ~/.bash_profile the following lines:

                            ## SCL Enabled Libraries
                            source /opt/rh/httpd24/enable
                        

PHP-FPM with Apache 2.4

Setup FPM pools

cd /opt/rh/php54/root/etc/php-fpm.d/

Make a new configuration for each site

cp www.conf domain.com.conf

Edit and setup values including chroot, port and listen address. Also environment variables, include path and other php related settings can be set per pool/site here.

Create a virtual host

cd /opt/rh/httpd24/root/etc/httpd/

vi conf.d/domain.com.conf

<VirtualHost *:80>

    ServerName domain.com
    ServerAlias domain.com www.domain.com
    ServerAdmin support@zvps.co.uk
    DocumentRoot "/var/www/html/domain.com/"

    RewriteEngine on

    <Directory "/var/www/html/domain.com">
        Options -Indexes +FollowSymLinks -MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/domain.com/$1
    ProxyPassMatch ^/(.*/)$ fcgi://127.0.0.1:9000/var/www/html/domain.com/index.php

    ErrorLog  ${APACHE_LOG_DIR}/domain.com-error.log
    CustomLog ${APACHE_LOG_DIR}/domain.com-access.log combined
    
</virtualhost>

Ports in the ProxyPassMatch need to match the pool configuration setup for this site / application in the fpm configuration.

Switching over Apache 2.2 / PHP 5.3 to Apache 2.4 / PHP 5.4 (FPM)

service php54-php-fpm start
service httpd stop
service httpd24-httpd start

http://developerblog.redhat.com/2013/08/01/php-5-4-on-rhel-6-using-rhscl/

Updating Apache 2.4.6 to 2.4.12

Download the latest httpd24 version from softwarecollections.org:

https://www.softwarecollections.org/en/scls/rhscl/httpd24/epel-6-x86_64/download/rhscl-httpd24-epel-6-x86_64.noarch.rpm

Add rpm to yum:

yum install rhscl-httpd24-epel-6-x86_64.noarch.rpm

Upgrade to 2.4.12:

yum update

If any rpmnew files are created diff and fix for example:

diff /opt/rh/httpd24/root/etc/httpd/conf/httpd.conf /opt/rh/httpd24/root/etc/httpd/conf/httpd.conf.rpmnew

Check running version:

httpd -version
httpd -t

Lastly check all sites are functioning.