Page 1 of 1

Run PHP4 *and* PHP5 on a single apache installation

Posted: Wed Nov 02, 2005 5:39 pm
by Chris Corbyn
Is it possible?

Obviously I'm talking about having virt. hosts and loading the relevant module for each host in httpd.conf. I'm not sure you can do that though... can you?

Failing that I'll just run two servers on different ports, but that's not what I'm looking for :(

Posted: Wed Nov 02, 2005 5:58 pm
by timvw
I think the easiest solution is to run one as mod_php and the other through cgi-bin (meaby you can make it faster with mod_fastcgi).

Posted: Wed Nov 02, 2005 6:18 pm
by programmermatt

Code: Select all

AddHandler application/x-httpd-php4 .php
AddHandler application/x-httpd-php5 .php5
In httpd.conf or, if your configuration allows, .htaccess will work. I have it run all scripts in php4, and if I need a php directory I just:

.htaccess

Code: Select all

AddHandler application/x-httpd-php5 .php
As it overwrites the httpd.conf setting

Posted: Wed Nov 02, 2005 6:30 pm
by Chris Corbyn
programmermatt wrote:

Code: Select all

AddHandler application/x-httpd-php4 .php
AddHandler application/x-httpd-php5 .php5
In httpd.conf or, if your configuration allows, .htaccess will work. I have it run all scripts in php4, and if I need a php directory I just:

.htaccess

Code: Select all

AddHandler application/x-httpd-php5 .php
As it overwrites the httpd.conf setting
Hadn't thought of that.

If I just load both modules in, have the default handler for .php as php5. Then I guess, in the relevant virtualhosts I can "AddHandler application/x-httpd-php4 .php" so long as it overrides the global setting. I would never need to use some php5 and some php4 files within the same directory :)

Good thinking thanks!

Posted: Wed Nov 02, 2005 7:07 pm
by Chris Corbyn
Doesn't work. Have you tried this? Be good to have a look at your httpd.conf if you have becuase I can't make it work :(

If I load both modules in all php scripts get ignored altogether (they dont execute).

Then if I add the handlers (I assume you have to add the mime-types too) they just offer to download.

I know I'm being dumb and it is 1 O'clock in the morning, but it kinda made sense that it doesn't work so I didn't look into much.

Thanks for the help, be good if you could post your httpd.conf :)

Code: Select all

LoadModule access_module modules/mod_access.so
LoadModule auth_module modules/mod_auth.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule expires_module modules/mod_expires.so
LoadModule setenvif_module modules/mod_setenvif.so
<IfDefine SSL>
LoadModule ssl_module modules/mod_ssl.so
</IfDefine>
LoadModule mime_module modules/mod_mime.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule asis_module modules/mod_asis.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
#LoadModule imap_module modules/mod_imap.so
LoadModule actions_module modules/mod_actions.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module        modules/libphp5.so
LoadModule php4_module        modules/libphp4.so

# ......

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php5 .php .php5

AddHandler php-script .php .php5
#Also tried
AddHandler application/x-httpd-php5 .php .php5

Posted: Wed Nov 02, 2005 7:17 pm
by timvw
I've been looking at this topic for over a year now, and i would be surprised if that would be possible :p

Fe, read http://svn.gnqs.org/projects/gentoo-php ... format=raw

Posted: Wed Nov 02, 2005 7:33 pm
by RobertPaul
Here's how I do it. I have PHP4 set up normally (via mod_php). Then I have two virtual hosts set up for PHP5.0 and PHP5.1 ... like so:

Code: Select all

Listen 80
Listen 81
Listen 82
<VirtualHost *:81>
	ServerName localhost
	ServerAdmin me@localhost
	DirectoryIndex index.html index.php
	ErrorLog logs/error.log
	DocumentRoot "D:/webroot/"
	ScriptAlias /cgi-bin/ "C:/php5/"
	Action php5-script /cgi-bin/php-cgi.exe
	AddHandler php5-script .php
</VirtualHost>
<VirtualHost *:82>
	ServerName localhost
	ServerAdmin me@localhost
	DirectoryIndex index.html index.php
	ErrorLog logs/error.log
	DocumentRoot "D:/webroot/"
	ScriptAlias /cgi-bin/ "C:/php51/"
	Action php5-script /cgi-bin/php-cgi.exe
	AddHandler php5-script .php
</VirtualHost>
I can't guarantee that this is the best way. It "Just Works™." And that's all I need. And it's nice since I don't have specific handlers (say .php4, .php5) I can easily test my code on different PHP versions just by adding the port number.

Posted: Wed Nov 02, 2005 7:36 pm
by Chris Corbyn
timvw wrote:I've been looking at this topic for over a year now, and i would be surprised if that would be possible :p

Fe, read http://svn.gnqs.org/projects/gentoo-php ... format=raw
Hmmm... Poo :(

I'll go down the cgi root then. Using mod_proxy with two instances of apache running is a waste of memory usage IMO and just roundabout way to get a job done.

Someone should write a module for apache that's designed to handle this kind of task :) Quite surprised it's not been done, but then I guess if it could be done, it would have been done.

Thanks timvw ;)