RyanDoyle.net

home posts projects contact

PHP 5.3 on CentOS 5 with an existing mod_php installation

10 Nov 2010

I have seen many ways of installing newer versions of PHP on a CentOS/RHEL system. Most include replacing the distribution provided RPMs with 3rd party RPMs, replacing the entire PHP installation. I don’t like this as there is often only a few web applications that require a newer version of PHP.

I decided to build a stand-alone PHP 5.3 that will execute via CGI to run PHP scripts. This way, we can still have the distribution supplied PHP and mod_php installed with Apache, but we can override mod_php and use the newer PHP 5.3 on a per vhost basis.

The entire PHP 5.3 installation is under /opt/php53 so it will not interfere with existing PHP installations. Lets go about installing it by first installing my YUM repository.

wget http://files.doylenet.net/linux/packages/rhel/5/doylenet/\
  RPMS/x86_64/doylenet-repo-rhel5-1.0-1.noarch.rpm
rpm -Uvh doylenet-repo-rhel5-1.0-1.noarch.rpm

It will depend on yum-priorities just to make sure my repository isn’t going to override any distribution provided packages. You really should already have this in place if you are installing any 3rd party repository.

Next install php53 and any php53 extensions you might want

yum install php53 php53-mysql php53-mbstring php53-mcrypt

Now finally you will need to configure Apache to use our new PHP. You will need to do this on a per vhost basis if the existing distribution PHP is installed. Otherwise it can be configure outside of a vhost.

<VirtualHost *:80>

  DocumentRoot /var/www/html/roundcubemail-0.4.2
  ServerName "webmail.example.com"

  <IfModule alias_module>
    ScriptAlias /cgi-php/ "/opt/php53/bin/"
  </IfModule>

  <Directory "/opt/php53/bin/">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
  </Directory>

  AddHandler php-cgi .php
  Action php-cgi "/cgi-php/php-cgi"

</VirtualHost>

I have only compiled the x86_64 version as that is all I have installed on my servers. I have provided the SRPM if you need to compile your own i386 version. This is fairly “beta” at the moment as I haven’t fully tested all the features and extensions of PHP. It shouldn’t break anything as the install is in its own path and does not appear in the $PATH variable but I can’t guarantee this. If you need an extension that I have not enabled, please let me know and I’ll see what I can do.



comments powered by Disqus

2023 - Ryan Doyle - Powered by Jekyll