Web Hosting Talk







View Full Version : Run PHP4 (module) & PHP5 (fastcgi) simultaneously on Fedora (Apache 2)


Serberus
04-29-2006, 04:34 PM
I've spent a few hours compiling information from around the net to get PHP4 & PHP5 working simultaneously. I thought I'd write up what I had to do and hope this can help others. This isn't rocket science but at least this consolidates the information I had to search for...

Note: This is not a set up you might use for a sharing hosting scenario, this is just for my colo server where Apache runs under a 'www' user, and friends I host don't have SSH. For a more secure set up you'd probably want to use suphp / SuExec etc.

I'm assuming you've already got PHP4 happily running as an Apache module. These instructions only cover installing FastCGI, PHP5 & configuration.

Grab a copy of FastCGI & mod_fastcgi, extract these and install. (I can't provide the correct links because I've currently got under 5 posts)

cd /usr/src/
wget fastcgi.com/dist/fcgi-2.4.0.tar.gz
wget fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
tar xzf fcgi-2.4.0.tar.gz
tar xzf mod_fastcgi-2.4.2.tar.gz
cd fcgi-2.4.0
./configure && make && make install
cd ../cd mod_fastcgi-2.4.2
It's documented on fastcgi.com (fastcgi.com/mod_fastcgi/INSTALL) to perform the following... HOWEVER:
<mod_fastcgi_dir>$ apxs -o mod_fastcgi.so -c *.c
<mod_fastcgi_dir>$ apxs -i -a -n fastcgi mod_fastcgi.so
... this did not work for me (not sure if those are instructions for Apache 1.3.x), so I had to do this:cp Makefile.AP2 Makefile
make && make install
If you were successful you'll see 'mod_fastcgi.so' in your Apache modules dir. In my case:ls -l /usr/local/apache2/modules/
-rw-r--r-- 1 root root 8440 Feb 28 2005 httpd.exp
-rwxr-xr-x 1 root root 345172 Apr 29 16:54 mod_fastcgi.so
-rwxr-xr-x 1 root root 140451 Feb 6 2005 mod_rewrite.so
Check that this line exists in your httpd.conf (typically it should be found near the top with other LoadModule statements):LoadModule fastcgi_module modules/mod_fastcgi.so
Now we need to configure FastCGI.mkdir -p /tmp/fcgi_ipc/dynamic
chmod -R 777 /tmp/fcgi_ipc/
Next edit your httpd.conf and add the following.

In my conf file I added this line in the 'ScriptAlias' section just below the ServerSignature directive.

This line is optional but if you choose not to include it, apache will check the document root of the current site - this gives you per site configuration of Fast CGI; for me it was overkill and I only needed one file to define these settings so I aliased it and put the config file in apache's cgi-bin dir.ScriptAlias /php5.fcgi "/usr/local/apache2/cgi-bin/php5.fcgi"
Above my 'AddIcon' directives I added the following to configure FastCGI. The bottom line is optional, see the documentation for explanation of these settings - I borrowed these from here: timdorr.com/archives/2006/02/php4_and_php4_s.php
# FastCGI directives
<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi
FastCgiIpcDir /tmp/fcgi_ipc/
FastCgiConfig -autoUpdate -singleThreshold 100 -killInterval 300 -idle-timeout 240 -pass-header HTTP_AUTHORIZATION
</IfModule>
Add these lines below your PHP4 'AddType' directives to bind the .php5 file extension to your FastCGI config script 'php5.fcgi':AddHandler application/x-httpd-php5 .php5
Action application/x-httpd-php5 /php5.fcgiNext create your 'php5.fcgi' and add the following:#!/bin/sh
PHP_FCGI_CHILDREN=2
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec /usr/local/php5/bin/phpMake sure 'php5.fcgi' has the correct permissions & user/group so Apache can access it. Apache runs under 'www' on my box, please specify the appropriate user & group.chown www:www php5.fcgi
chmod 755 php5.fcgiNow it's time to install PHP5. It's probably worth matching your PHP4 configure line which can be found on the phpinfo() page. To find out the available configure options type './configure --help'. Whats important are the configure switches I've shown and that you specify a prefix path to install PHP5.cd /usr/src
wget uk.php.net/get/php-5.1.2.tar.bz2/from/this/mirror
tar xjf php-5.1.2.tar.bz2
cd php-5.1.2
./configure --with-config-file-path=/usr/local/php5/php.ini --prefix=/usr/local/php5 --enable-fastcgi --enable-discard-path --enable-force-cgi-redirect ...your switches...
make && make install
cp php.ini-dist /usr/local/php5/php.iniYou can check the installation was successful:/usr/local/php5/bin/php -vYou should see:
PHP 5.1.2 (cgi-fcgi) (built: Apr 29 2006 17:40:57)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend TechnologiesNow restart apache. Then create a phpinfo() page with the extension .php5 (eg. phpinfo.php5 - don't forget to remove this once you've confirmed PHP5 is running successfully!)

If this hasn't worked check the modules Apache has loaded, specifically mod_action./usr/local/apache2/bin/apachectl -l

Hopefully you've now got PHP5 running along side PHP4!

Sources of reference:
www fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html
plone.org/documentation/tutorial/plone-apache/fastcgi
wiki.rubyonrails.com/rails/pages/RailsOnFedora
timdorr.com/archives/2006/02/php4_and_php4_s.php
www howtoforge.com/apache2_with_php5_and_php4_p2

henmar
09-20-2006, 07:31 AM
I have fedora 4 installed in my and it has php5 as default installation. But i want php4 aslo to be installed. So can i follow the above procedure to run both.
thanks

alMubarmij
11-22-2008, 02:16 PM
Thank you.
Is there is another easiest way ?

Steve_Arm
11-22-2008, 02:41 PM
The correct command to compile mod_fastcgi is:
apxs -a -o mod_fastcgi -c *.c
which will also add the httpd.conf entry

You can find additional information here:
http://www.openmvc.com/2008/09/27/setting-up-apache-php-fastcgi/
This uses per virtual host php configuration

Cristi4n
11-22-2008, 07:30 PM
you can also run one instance of apache with mod_php4 and mod_php5 at the same time (.php for both) and all you need to do is using different ips for sites that need php4 and sites that need php5.