Docs/Howto/Networking/Apache PHP4 PHP5

From Mandriva Community Wiki

Jump to: navigation, search
Using Apache with PHP4 and PHP5 at the same time

This is an example showing how you can run apache with php4 and php5 at the same time, on the same machine.

People ask me how to run apache with php4 and php5 at the same time. Well, it generally can't be done because the mod_php[45] modules will conflict internally (symbol clashes). The trick is to run apache in a second instance on a different port or using dedicated ip addresses for each apache instance. To do this you need to get root and do some manual tasks outlined below:

# urpmi apache-mod_php4
# mv /etc/httpd/modules.d/70_mod_php4.conf /etc/httpd/conf/
# ln -s /usr/sbin/httpd /usr/sbin/httpd-php4
# cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd-php4.conf

Apply these changes to the new httpd-php4.conf file:

--- httpd.conf  2005-08-30 06:25:31.000000000 +0200
+++ httpd-php4.conf     2005-09-22 12:58:04.000000000 +0200
@@ -71,7 +71,7 @@
 # PidFile: The file in which the server should record its process
 # identification number when it starts.
 #
-PidFile /var/run/httpd.pid
+PidFile /var/run/httpd-php4.pid

 #
 # Timeout: The number of seconds before receives and sends time out.
@@ -176,7 +176,7 @@
 #
 #Listen 12.34.56.78:80

-Listen 0.0.0.0:80
+Listen 0.0.0.0:88

 #
 # Dynamic Shared Object (DSO) Support
@@ -244,7 +244,7 @@

 # Bring in additional module-specific configurations
 #
-Include modules.d/*.conf
+Include conf/70_mod_php4.conf

 # include legacy conf.d during a transition period
 Include conf.d/*.conf
@@ -470,7 +470,7 @@
 # logged here.  If you *do* define an error logfile for a <VirtualHost>
 # container, that host's errors will be logged there and not here.
 #
-ErrorLog logs/error_log
+ErrorLog logs/php4_error_log

 #
 # LogLevel: Control the number of messages logged to the error_log.
@@ -505,7 +505,7 @@
     # define per-<VirtualHost> access logfiles, transactions will be
     # logged therein and *not* in this file.
     #
-    CustomLog logs/access_log common
+    CustomLog logs/php4_access_log common

     #
     # If you would like to have agent and referer logfiles, uncomment the

Next, make a copy of the httpd initscript:

# cp -p /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd-php4

Apply these changes to the new httpd-php4 initscript:

--- httpd       2005-08-30 06:25:31.000000000 +0200
+++ httpd-php4  2005-09-22 12:31:02.000000000 +0200
@@ -17,8 +17,8 @@
 . /etc/rc.d/init.d/functions

 # Source the /etc/sysconfig/httpd file.
-if [ -f /etc/sysconfig/httpd ]; then
-    . /etc/sysconfig/httpd
+if [ -f /etc/sysconfig/httpd-php4 ]; then
+    . /etc/sysconfig/httpd-php4
 fi

 # Start httpd in the C locale by default.
@@ -31,9 +31,9 @@
 export TMPDIR=${HTTPD_TMPDIR:-"/tmp"}

 # Start with defaults
-httpdpid=${HTTPDPID:-"/var/run/httpd.pid"}
+httpdpid=${HTTPDPID:-"/var/run/httpd-php4.pid"}
 options=${OPTIONS-""}
-httpd=${HTTPD:-"/usr/sbin/httpd"}
+httpd=${HTTPD:-"/usr/sbin/httpd-php4"}
 statusurl=${STATUSURL:-"http://localhost/server-status"}

 ## Number of times to try to start Apache in case of error
@@ -91,7 +91,7 @@

 detect() {
    detectlib
-   httpdconf=${HTTPDCONF:-"-f /etc/httpd/conf/httpd.conf"}
+   httpdconf=${HTTPDCONF:-"-f /etc/httpd/conf/httpd-php4.conf"}
    extramodules="-DAPACHE2 `extramoduleargs /etc/httpd/extramodules`"
    modules=`moduleargs /etc/httpd/modules`
    debug=${DEBUG:-"-DNO_DETACH -DONE_PROCESS -DDEBUG"}
@@ -163,7 +163,7 @@
        # set safe temp
        for tries in $times_start; do
          if [ -x $httpd -a ! -e $httpdpid ]; then
-               if [ $tries -eq 1 ]; then echo -n "Starting httpd: ";fi
+               if [ $tries -eq 1 ]; then echo -n "Starting httpd-php4: ";fi
                sanitizer; semdetect
                daemon $httpd $httpdconf $extramodules $modules $options
                echo
@@ -172,7 +172,7 @@
                done
          fi
        done
-       touch /var/lock/subsys/httpd
+       touch /var/lock/subsys/httpd-php4
 }

 # OE: 20040610 run the whole shebang in the foreground which will
@@ -181,9 +181,9 @@
 debugstart() {
        for tries in $times_start; do
          if [ -x $httpd -a ! -e $httpdpid ]; then
-               if [ $tries -eq 1 ]; then echo -n "Starting httpd: ";fi
+               if [ $tries -eq 1 ]; then echo -n "Starting httpd-php4: ";fi
                $httpd $httpdconf $debug \
-               -c "Pidfile /tmp/httpd-debug.pid" \
+               -c "Pidfile /tmp/httpd-php4-debug.pid" \
                -c "LogLevel debug" \
                -c "ErrorLog /dev/stdout" \
                -c "CustomLog /dev/stdout common" \
@@ -194,25 +194,25 @@
                done
          fi
        done
-       touch /var/lock/subsys/httpd
+       touch /var/lock/subsys/httpd-php4
 }

 stop() {
        if [ -e $httpdpid ]; then
-               echo -n "Shutting down httpd: "
-               killproc httpd
+               echo -n "Shutting down httpd-php4: "
+               killproc httpd-php4
                echo
                if [ -e $libdir/apache-extramodules/mod_jserv.so ]; then
                        snooze
                        while [ -e $httpdpid ]; do
                                echo Trying harder
                                snooze
-                               killproc httpd
+                               killproc httpd-php4
                        done
                fi
                rm -f $httpdpid
        fi
-       rm -f /var/lock/subsys/httpd
+       rm -f /var/lock/subsys/httpd-php4
 }

 # See how we were called.
@@ -237,7 +237,7 @@
        echo
        if [ -e $httpdpid ]; then
                echo "Apache is running."
-               echo "httpd: `pidof httpd`"
+               echo "httpd-php4: `pidof httpd-php4`"
                echo
        fi
        if [ ! -e $httpdpid ]; then
@@ -265,8 +265,8 @@
        else
                 detect
                if [ -e $httpdpid ]; then
-                       echo -n "Reloading httpd: "
-                       killproc httpd -USR1
+                       echo -n "Reloading httpd-php4: "
+                       killproc httpd-php4 -USR1
                        echo
                fi
        fi
@@ -274,8 +274,8 @@
   closelogs)
         detect
        if [ -e $httpdpid ]; then
-               echo -n "Sending HUP to httpd: "
-               killproc httpd -HUP
+               echo -n "Sending HUP to httpd-php4: "
+               killproc httpd-php4 -HUP
                echo
        fi
        ;;

Finally, add and start the service:

# chkconfig --add httpd-php4
# chkconfig httpd-php4 on
# service httpd-php4 start

That's it.

Personal tools