
02-10-2006, 01:57 AM
|
|
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.
|

02-13-2006, 06:59 PM
|
|
Aspiring Evangelist
|
|
Join Date: Sep 2000
Location: New Jersey
Posts: 366
|
|
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);
|

03-15-2006, 06:03 AM
|
|
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
|

03-21-2006, 07:06 PM
|
|
Junior Guru Wannabe
|
|
Join Date: Aug 2004
Posts: 48
|
|
Nice think to share !!!
Thanks
|

04-29-2006, 10:54 AM
|
|
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
|

05-19-2006, 03:40 PM
|
|
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.
|

05-24-2006, 01:38 PM
|
|
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.
|

05-25-2006, 11:51 PM
|
|
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
|

05-26-2006, 05:39 AM
|
|
Newbie
|
|
Join Date: Apr 2006
Posts: 12
|
|
Thanks! I'm going to try it on my test webserver... :-D
|

05-28-2006, 10:38 AM
|
|
Newbie
|
|
Join Date: Mar 2006
Location: Canada
Posts: 19
|
|
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.
|

06-04-2006, 02:02 AM
|
|
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
|

06-04-2006, 03:25 AM
|
|
Junior Guru Wannabe
|
|
Join Date: Jan 2005
Location: Kingdom of Bahrain
Posts: 56
|
|
|

06-13-2006, 02:40 PM
|
|
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.
|

06-13-2006, 03:03 PM
|
|
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
|

06-13-2006, 03:38 PM
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| 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
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|