hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : Hosting Security and Technology Tutorials : How To: Run PHP4 and PHP5 on the same server
Reply

Hosting Security and Technology Tutorials Tutorials related to server security or the like.
Forum Jump

How To: Run PHP4 and PHP5 on the same server

Reply Post New Thread In Hosting Security and Technology Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 02-10-2006, 01:57 AM
JonnyQuags JonnyQuags is offline
Aspiring Evangelist
 
Join Date: Sep 2000
Location: New Jersey
Posts: 366

How To: Run PHP4 and PHP5 on the same server


I wanted to get both PHP4 and PHP5 working on the same server. For sanity reasons I would not consider forcing any clients to change to PHP5 and risk breaking scripts. Running PHP as a cgi was also not an option and I did not want to run a second webserver or do anything with a proxy. Below is the solution for this by allowing both php4 and php5 to run as apache modules.

1) Download PHP 5.1.2 from php.net and extract

2) apply the following patch

Code:
--- php-5.1.2/sapi/apache/mod_php5.c	2006-01-06 13:06:38.000000000 -0500
+++ php-5.1.2/sapi/apache/mod_php5.c.new	2006-02-07 15:51:31.000000000 -0500
@@ -929,8 +929,8 @@
  */
 handler_rec php_handlers[] =
 {
-	{"application/x-httpd-php", send_parsed_php},
-	{"application/x-httpd-php-source", send_parsed_php_source},
+	{"application/x-httpd-php5", send_parsed_php},
+	{"application/x-httpd-php5-source", send_parsed_php_source},
 	{"text/html", php_xbithack_handler},
 	{NULL}
 };
@@ -940,10 +940,10 @@
  */
 command_rec php_commands[] =
 {
-	{"php_value",		php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"},
-	{"php_flag",		php_apache_flag_handler, NULL, OR_OPTIONS, TAKE2, "PHP Flag Modifier"},
-	{"php_admin_value",	php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Value Modifier (Admin)"},
-	{"php_admin_flag",	php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Flag Modifier (Admin)"},
+	{"php5_value",		php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"},
+	{"php5_flag",		php_apache_flag_handler, NULL, OR_OPTIONS, TAKE2, "PHP Flag Modifier"},
+	{"php5_admin_value",	php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Value Modifier (Admin)"},
+	{"php5_admin_flag",	php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Flag Modifier (Admin)"},
 	{NULL}
 };
 /* }}} */

Save the file a directory above the php 5.1.2 directory as php5-sapi.patch (any name can do)

3) Apply the patch (patch -p1 < ../php5-sapi.patch)

/--(root@acute):[/home/quags/php5]-[pts/4]-(12:46am)
\-> cd php-5.1.2
/--(root@acute):[/home/quags/php5/php-5.1.2]-[pts/4]-(12:46am)
\-> patch -p1 < ../php5-sapi.patch
patching file sapi/apache/mod_php5.c


4) Compile php as in a new directory such as /usr/local/php5

./configure --with-apxs=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php5 --prefix=/usr/local/php5 ...etc

You'll probably want to use the same php compile line as php4. Get that from php info or you can try the command
strings `which php` | grep ./configure | sed s#"'"#""#g

5) Finish the install with make, make install and install the php.ini file with

cp php.ini-dist /usr/local/php5/etc/php.ini

You should now have the following in httpd.conf
LoadModule php4_module libexec/libphp4.so
LoadModule php5_module libexec/libphp5.so

AddModule mod_php4.c
AddModule mod_php5.c


Then add the handler for php5

AddType application/x-httpd-php5 .php5
AddType application/x-httpd-php5-source .php5s

and finally restart apache.



I have not seen any issues so far with this setup or seen any slowdown. I'm sure there is extra overhead by having two mod_php's loaded but its a nice way to offer php5 without forcing any upgrade server wide.

Reply With Quote


Sponsored Links
  #2  
Old 02-13-2006, 06:59 PM
JonnyQuags JonnyQuags is offline
Aspiring Evangelist
 
Join Date: Sep 2000
Location: New Jersey
Posts: 366
Apache2

The above patch is for Apache1. I was asked how to do the same for apache2. The patch is included below and has been tested on apache 2.0. Compile with --with-apxs2=apxs where apxs is the patch to your apxs file.


Code:
--- php-5.1.2/sapi/apache2filter/apache_config.c	2006-01-01 07:50:18.000000000 -0500
+++ php-5.1.2/sapi/apache2filter/apache_config.c.new	2006-02-13 17:35:26.000000000 -0500
@@ -186,13 +186,13 @@
 
 const command_rec php_dir_cmds[] =
 {
-	AP_INIT_TAKE2("php_value", php_apache_value_handler, NULL, OR_OPTIONS,
+	AP_INIT_TAKE2("php5_value", php_apache_value_handler, NULL, OR_OPTIONS,
                   "PHP Value Modifier"),
-	AP_INIT_TAKE2("php_flag", php_apache_flag_handler, NULL, OR_OPTIONS,
+	AP_INIT_TAKE2("php5_flag", php_apache_flag_handler, NULL, OR_OPTIONS,
                   "PHP Flag Modifier"),
-	AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL, 
+	AP_INIT_TAKE2("php5_admin_value", php_apache_admin_value_handler, NULL, 
 			ACCESS_CONF|RSRC_CONF, "PHP Value Modifier (Admin)"),
-	AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL, 
+	AP_INIT_TAKE2("php5_admin_flag", php_apache_admin_flag_handler, NULL, 
 			ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"),
 	AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF,
                   "Directory containing the php.ini file"),
--- php-5.1.2/sapi/apache2handler/apache_config.c	2006-01-01 07:50:18.000000000 -0500
+++ php-5.1.2/sapi/apache2handler/apache_config.c.new	2006-02-13 17:35:57.000000000 -0500
@@ -174,10 +174,10 @@
 
 const command_rec php_dir_cmds[] =
 {
-	AP_INIT_TAKE2("php_value", php_apache_value_handler, NULL, OR_OPTIONS, "PHP Value Modifier"),
-	AP_INIT_TAKE2("php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, "PHP Flag Modifier"),
-	AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Value Modifier (Admin)"),
-	AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"),
+	AP_INIT_TAKE2("php5_value", php_apache_value_handler, NULL, OR_OPTIONS, "PHP Value Modifier"),
+	AP_INIT_TAKE2("php5_flag", php_apache_flag_handler, NULL, OR_OPTIONS, "PHP Flag Modifier"),
+	AP_INIT_TAKE2("php5_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Value Modifier (Admin)"),
+	AP_INIT_TAKE2("php5_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"),
 	AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, "Directory containing the php.ini file"),
 	{NULL}
 };
--- php-5.1.2/sapi/apache2handler/sapi_apache2.c	2006-02-13 17:33:39.000000000 -0500
+++ php-5.1.2/sapi/apache2handler/sapi_apache2.c.new	2006-02-13 17:34:00.000000000 -0500
@@ -59,8 +59,8 @@
  */
 #undef shutdown
 
-#define PHP_MAGIC_TYPE "application/x-httpd-php"
-#define PHP_SOURCE_MAGIC_TYPE "application/x-httpd-php-source"
+#define PHP_MAGIC_TYPE "application/x-httpd-php5"
+#define PHP_SOURCE_MAGIC_TYPE "application/x-httpd-php5-source"
 #define PHP_SCRIPT "php5-script"
 
 /* A way to specify the location of the php.ini dir in an apache directive */
--- php-5.1.2/sapi/apache_hooks/mod_php5.c	2006-01-01 07:50:18.000000000 -0500
+++ php-5.1.2/sapi/apache_hooks/mod_php5.c.new	2006-02-13 17:33:04.000000000 -0500
@@ -1393,8 +1393,8 @@
  */
 handler_rec php_handlers[] =
 {
-	{"application/x-httpd-php", send_parsed_php},
-	{"application/x-httpd-php-source", send_parsed_php_source},
+	{"application/x-httpd-php5", send_parsed_php},
+	{"application/x-httpd-php5-source", send_parsed_php_source},
 	{"text/html", php_xbithack_handler},
 		{"php-script", php_response_handler},
 	{NULL}
@@ -1405,7 +1405,7 @@
  */
 command_rec php_commands[] =
 {
-	{"php_value",		php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"},
+	{"php5_value",		php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"},
 	{"phpUriHandler",		php_set_uri_handler, NULL, RSRC_CONF, TAKE1, "PHP Value Modifier"},
 	{"phpUriHandlerMethod",		php_set_uri_handler_code, NULL, RSRC_CONF, TAKE1, "PHP Value Modifier"},
 #if MODULE_MAGIC_NUMBER >= 19970103
--- php-5.1.2/sapi/apache/mod_php5.c	2006-01-06 13:06:38.000000000 -0500
+++ php-5.1.2/sapi/apache/mod_php5.c.new	2006-02-07 15:51:31.000000000 -0500
@@ -929,8 +929,8 @@
  */
 handler_rec php_handlers[] =
 {
-	{"application/x-httpd-php", send_parsed_php},
-	{"application/x-httpd-php-source", send_parsed_php_source},
+	{"application/x-httpd-php5", send_parsed_php},
+	{"application/x-httpd-php5-source", send_parsed_php_source},
 	{"text/html", php_xbithack_handler},
 	{NULL}
 };
@@ -940,10 +940,10 @@
  */
 command_rec php_commands[] =
 {
-	{"php_value",		php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"},
-	{"php_flag",		php_apache_flag_handler, NULL, OR_OPTIONS, TAKE2, "PHP Flag Modifier"},
-	{"php_admin_value",	php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Value Modifier (Admin)"},
-	{"php_admin_flag",	php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Flag Modifier (Admin)"},
+	{"php5_value",		php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"},
+	{"php5_flag",		php_apache_flag_handler, NULL, OR_OPTIONS, TAKE2, "PHP Flag Modifier"},
+	{"php5_admin_value",	php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Value Modifier (Admin)"},
+	{"php5_admin_flag",	php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Flag Modifier (Admin)"},
 	{NULL}
 };
 /* }}} */
--- php-5.1.2/sapi/apache2filter/sapi_apache2.c	2006-01-01 07:50:18.000000000 -0500
+++ php-5.1.2/sapi/apache2filter/sapi_apache2.c.new	2006-02-13 17:32:18.000000000 -0500
@@ -513,7 +513,7 @@
 			apr_file_name_get(&path, ((apr_bucket_file *) b->data)->fd);
 			
 			/* Determine if we need to parse the file or show the source */
-			if (strncmp(ctx->r->handler, "application/x-httpd-php-source", sizeof("application/x-httpd-php-source"))) { 
+			if (strncmp(ctx->r->handler, "application/x-httpd-php5-source", sizeof("application/x-httpd-php5-source"))) { 
 				zfd.type = ZEND_HANDLE_FILENAME;
 				zfd.filename = (char *) path;
 				zfd.free_filename = 0;
@@ -653,9 +653,9 @@
 
 static void php_insert_filter(request_rec *r)
 {
-	int content_type_len = strlen("application/x-httpd-php");
+	int content_type_len = strlen("application/x-httpd-php5");
 
-	if (r->content_type && !strncmp(r->content_type, "application/x-httpd-php", content_type_len-1)) {
+	if (r->content_type && !strncmp(r->content_type, "application/x-httpd-php5", content_type_len-1)) {
 		if (r->content_type[content_type_len] == '\0' || !strncmp(r->content_type+content_type_len, "-source", sizeof("-source"))) { 
 			php_add_filter(r, r->output_filters);
 			php_add_filter(r, r->input_filters);

Reply With Quote
  #3  
Old 03-15-2006, 06:03 AM
Fluke571 Fluke571 is offline
New Member
 
Join Date: Mar 2006
Posts: 0
Hi, thanks for the patch, however it didn't work for me :/
after patching 5.1.2 and installing it to separate location apache segfaults on every .php page... testing with plain phpinfo();

[Wed Mar 15 10:59:12 2006] [notice] child pid 24583 exit signal Segmentation fault (11)
[Wed Mar 15 10:59:14 2006] [notice] child pid 24584 exit signal Segmentation fault (11)
[Wed Mar 15 10:59:16 2006] [notice] child pid 24585 exit signal Segmentation fault (11)

if only one of the modules is present, it works... any ideas?

system is slackware-current, glibc 2.3.6, gcc 3.3.6, httpd-2.0.55

Reply With Quote
Sponsored Links
  #4  
Old 03-21-2006, 07:06 PM
inforassist inforassist is offline
Junior Guru Wannabe
 
Join Date: Aug 2004
Posts: 48
Nice think to share !!!
Thanks

Reply With Quote
  #5  
Old 04-29-2006, 10:54 AM
Serberus Serberus is offline
New Member
 
Join Date: Mar 2004
Location: Herts, UK
Posts: 1
I am also receiving segmentation faults when viewing .php files. I applied your Apache2 patch file and followed your instructions.

When viewing sites the following is in my error_log:

[Sat Apr 29 15:38:16 2006] [notice] SIGHUP received. Attempting to restart
[Sat Apr 29 15:38:16 2006] [notice] Apache configured -- resuming normal operations
[Sat Apr 29 15:38:17 2006] [notice] child pid 17762 exit signal Segmentation fault (11)
[Sat Apr 29 15:38:17 2006] [notice] child pid 17763 exit signal Segmentation fault (11)
[Sat Apr 29 15:38:18 2006] [notice] child pid 17764 exit signal Segmentation fault (11)
etc...

Running Gentoo, Apache 2.0.52 & PHP 4.4.0

Reply With Quote
  #6  
Old 05-19-2006, 03:40 PM
JonnyQuags JonnyQuags is offline
Aspiring Evangelist
 
Join Date: Sep 2000
Location: New Jersey
Posts: 366
I haven't been able to reproduce this on apache2 yet. If someone can contact me with details on a server I can log into and see I would be more than happy to see whats going on.

Reply With Quote
  #7  
Old 05-24-2006, 01:38 PM
milkfloat milkfloat is offline
New Member
 
Join Date: May 2006
Posts: 1
I am trying to reproduce the success you had with apache 1.3 and have been unable to do so.

I am trying to use 4.3.11 and 5.1.2 with the patch applied below and getting nowhere.

I get the following error when starting apache with both modules enabled:

*** glibc detected *** double free or corruption: 0x08517550 ***

If you have any suggestions please let me know.

Reply With Quote
  #8  
Old 05-25-2006, 11:51 PM
JonnyQuags JonnyQuags is offline
Aspiring Evangelist
 
Join Date: Sep 2000
Location: New Jersey
Posts: 366
Quote:
Originally Posted by milkfloat
*** glibc detected *** double free or corruption: 0x08517550 ***

If you have any suggestions please let me know.
Install zend optimizer version 2.6.2

Reply With Quote
  #9  
Old 05-26-2006, 05:39 AM
HostingScala HostingScala is offline
Newbie
 
Join Date: Apr 2006
Posts: 12
Thanks! I'm going to try it on my test webserver... :-D

Reply With Quote
  #10  
Old 05-28-2006, 10:38 AM
thanis thanis is offline
Newbie
 
Join Date: Mar 2006
Location: Canada
Posts: 19
Multiple PHPs

You can also remove the LoadModule php4/5 statements from httpd.conf, and add them instead to virtual hosts independently choosing whichever you want for each virtual host.

To do so, you'll need to compile each version of php its own directory.

Also, if you run scripts using php on the system (via shell or cron), make sure you point to the right php for what you are running.

I've done this a few times for people who were migrating and testing code between versions and who did not have a second server (or dev system) to test. It has always worked well, though if you do so make sure you document what you do so as not to mess up your system when it comes time to patch / update versions.

Reply With Quote
  #11  
Old 06-04-2006, 02:02 AM
Maze Hosting Maze Hosting is offline
Newbie
 
Join Date: Jun 2006
Posts: 5
I tired to install both PHP4 and PHP5 on the same server usuing easyapache from cPanel/WHM and I got many errors on loading PHP5

Reply With Quote
  #12  
Old 06-04-2006, 03:25 AM
seeker2002 seeker2002 is offline
Junior Guru Wannabe
 
Join Date: Jan 2005
Location: Kingdom of Bahrain
Posts: 56

Reply With Quote
  #13  
Old 06-13-2006, 02:40 PM
Steven Steven is online now
I like ice cream
 
Join Date: Mar 2003
Location: California USA
Posts: 11,591
stop spamming your tutorials where they are useless. That tutorial has nothing to do with this post.

Reply With Quote
  #14  
Old 06-13-2006, 03:03 PM
inforassist inforassist is offline
Junior Guru Wannabe
 
Join Date: Aug 2004
Posts: 48
If php 5 version is 5.1.4 the patch should be diferent right ?
What would the changes to do this patch ?

Regards

Reply With Quote
  #15  
Old 06-13-2006, 03:38 PM
JonnyQuags JonnyQuags is offline
Aspiring Evangelist
 
Join Date: Sep 2000
Location: New Jersey
Posts: 366
I have not tested with a later version of php. If the patch applies cleanly there should be no issues.

As an update to this tutorial I only recommend apache 2 / php4 and 5 on a test server first. As you can see above some user's are having seg faults with the patch which I am looking into.

For apache 1.3 and php4 and 5 I have yet to have any issues at all.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Web Host 1&1 Internet Adds Server Restoration Tool for Virtual Machines Web Hosting News 2012-11-07 15:45:16
Web Host OrcsWeb Offers Support for Windows Server 2012 Web Hosting News 2012-08-24 11:08:35
MochaHost Enhances Server Performance with Tomcat Native Library Accelerator Web Hosting News 2012-08-01 15:35:20
Web Host 1&1 Enhances Dedicated Server Line with 32 Core, 64 GB RAM Server Web Hosting News 2011-12-20 15:30:05
DiscountASP.NET Launches Free Beta for Microsoft SQL Server 2012 Hosting Web Hosting News 2011-12-13 22:02:03


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?