Question

I completed a php/mysql project for a client and yesterday went about to deploy it onto the client's box - and promptly failed. To be honest, it's my fault I didn't do enough checking before I started - but the project is fully self-contained and I didn't need anything currently on the client's server.

I developed the project using php 5.3 and PDO for mysql connection. When I got access to the client's server, turned out that they have VERY old installation that was last upgraded in 2008 (yes, seriously). They have Apache 2.0 and php 5.2, which is configured/compiled without PDO and with minimum everything.

I do have root access to the server, but I can't go and blindly start upgrading things. They've got a whole live site, with live shopping cart, etc. on that server and any general upgrade of php would require thorough testing. Therefore I'm looking at ways to run my new project using a separate install of php 5.3, which I compiled from sources with all required stuff included and installed into a separate directory (/opt/php53).

I am thinking along the lines of enabling fastcgi on the server and then using that to run php form my separate install. If I do this inside apache <Directory> where my project is install, it should only affect that one directory - and should leave everything else as is. Things are made more complicated because I don't have any kind of test server where I could play/test configurations - I have to work on the live server directly.

I'm wondering whether this fastcgi approach is valid or maybe there are some other options I should consider.

Was it helpful?

Solution 2

I've done some further digging/experimenting (taking advantage of the fact that I'm in UK and the client and its customers are in the USA - so it's still night there). The following setup seems to have worked - this utilises php-cgi without recourse to fastcgi - and I still get a good response time.

1) Leave pretty much everything intact in apache httpd.conf file - that includes existing libphp5.so that utilises existing 5.2 installation.

2) Install php 5.3 into a separate directory - in my case /opt/php53.

3) In httpd.conf, add the following (or ensure it's already there)

ScriptAlias /cgi-bin/ /var/www/mainsite/cgi-bin
AddHandler cgi-script .cgi

<Directory /var/www/mainsite/newapp>
    Options -Indexes FollowSymLinks +ExecCGI
    AllowOverride AuthConfig FileInfo
    AddHandler php5-cgi .php
    Action php5-cgi /cgi-bin/php.cgi
    DirectoryIndex index.php index.html
    Order allow,deny
    Allow from all
</Directory>

4) In directory /var/www/mainsite/cgi-bin/ create file php.cgi with the following content:

#!/bin/bash
PHP_CGI=/opt/php53/bin/php-cgi
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=1000
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI

5) Restart apache: /etc/init.d/httpd restart

After this, I placed a file with <?php phpinfo(); ?> into the root of the web server and into my newapp directory. Executed from the root of the server it produced (among other things):

PHP Version 5.2.5

Build Date  Dec 11 2008 19:04:47
Server API  Apache 2.0 Handler

When executed from the newapp directory, it produced:

PHP Version 5.3.28

Build Date  Feb 13 2014 17:00:43 
Server API  CGI/FastCGI 

Which is exactly what I want.

OTHER TIPS

You can try to use different ports on fastcgi for the various PHP versions.

Another approach: http://linuxplayer.org/2011/05/intall-multiple-version-of-php-on-one-server

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top