# Apache 2 with PHP5 and PHP4?

## ezekiel61

I need to have multiple versions of PHP running for new and old web applications. So I searched and found a thread that kinda beats around the bush. I have an idea, but I don't want to do it on my production server until I"ve talked it out with a few of you for feasibility.

1. Can we just emerge both mod_php4 and mod_php5  and add the directives in /etc/conf.d/apache for "-D PHP4 -D PHP5". Then let the apache module files handle it:

```

# Load the module first

        <IfModule !sapi_apache2.c>

                LoadModule php4_module    modules/libphp4.so

        </IfModule>

# Load the module first

        <IfModule !sapi_apache2.c>

                LoadModule php5_module    modules/libphp5.so

        </IfModule>

```

2. Handle it via the vhosts file? 

Not saying this will work, trying to get feedback to see if anyone has gotten something like this to work?

----------

## SilverOne

I'm interested in this as well.

I, too, have a production server that I don't want to put at too much risk with this.

I've got several virtual domains for others, and a couple for myself.

Now I want to develop PHP5 scripts on that server, but I don't want to upgrade everybody's PHP version.

So I'm looking to try running both PHP5 and PHP4 on the same (web-)server.

Either one of 2 situations will suit me:

- scripts with .php or .php4 will be run by php4  and scripts with .php5 will be run by php5

- all .php/.php4/.php5 scripts on domains x,y,z will be run by php5, all scripts on other domains will be run by php4

(though if both we're possible I'd choose to allow only .php5 on domains x,y,z to be run by PHP5)

How does one go about this?

I searched the forum but all I got was threads about conflicts, and not much about getting it to work.  We can't be the only 2 who'd want this?

Thanks for any tips!

EDIT: I'm running apache 2

----------

## ezekiel61

I haven't spent much time on this since I originally posted. I did find an apache project called XAMPP at http://www.apachefriends.org/en. This is a Windows Apache project. However, if you install it they claim to run both PHP4 and PHP5 along with other Apache projects such as Tomcat and Cocoon. I suppose if one were to install this and check out how they setup their htttpd.conf file we could figure this out... as of right now I don't have the time to do it. I'll update if I get any progress.

----------

## SilverOne

From what I gathered they we're using some third-party add-on.

I've also seen people modify the PHP5 modules source (to get different handle names) or use it as CGI.

The option that is also offered (and appeals to me most) is running 2 apache daemons on the same machine.

I would like to know how I can do this within reasonable hacking distance of regular portage-based system maintenance though.

(preferably I'd like to be able to update any and all software via portage, including any second installation of Apache).

I'll take a look at this in the coming days...

----------

## rsevero

I've installed PHP5 as FastCGI. mod_php(4) got untouched.

It isn't optimal but it's working for me right now.

----------

## SilverOne

 *rsevero wrote:*   

> I've installed PHP5 as FastCGI. mod_php(4) got untouched.
> 
> It isn't optimal but it's working for me right now.

 

I heard there we're security and other problems with running PHP as CGI  (including access to some server variables)

I therefore concluded this method was not a true companion to PHP4....  (I want to be able to switch back and forth from PHP4 to 5, in order to test existing scripts.).

Is there a list of differences between mod_php and cgi_php?  

I'm still thinking about the 2 apache daemons, I'll post a separate thread for this.

----------

## arut8ur

Hi

I have the same Problem, need to run PHP4 and PHP5 on the same server.

What I did is to run 2 apache instances on different IPs with the same configuration. 

So I can access the same VHosts with www.mydomain (PHP4) and php5.mydomain (PHP5),..

Now I can check the same project-code against PHP4 an PHP5.

To do this I did the following:

Setup a new IP addres for my NIC. 

You can do this easily if you are using /etc/conf.d/net to setup your IP Addrsses, I am using DHCP so I used this entry in /etc/conf.d/local.start "ifconfig eth0 add 172.25.0.9"

Now I installed PHP5 from source, because the Portage ebuild for PHP5 are outdated. For PHP4 I am using the portage ebuilds.

After comiling PHP5 I copied the modules (libphp5.so, libphp5.la) to /usr/lib/apache2/modules.

Now I copied /etc/apache2/conf/modules.d/70_mod_php.conf to /etc/apache2/conf/modules.d/71_mod_php5.conf and modified it for PHP5.

Now I copied /etc/conf.d/apache2 /etc/conf.d/apache2_php5 and change the some values:

```
APACHE2_OPTS="-D SSL -D PHP5 -D LDAP -D AUTH_LDAP"

STARTUPERRORLOG="/var/log/apache2_php5/startuperror.log"

PIDFILE=/var/run/apache2_php5.pid
```

Now I copied /etc/init.d/apache2 to /etc/init.d/apche2_php5.

In my /etc/apache/conf/apache2.conf I configured the IP Addresses with

```
<IfDefine PHP4>

   Listen 172.25.0.7:80

</IfDefine>

<IfDefine PHP5>

   Listen 172.25.0.9:80

</IfDefine>
```

This Setup is not perfect, because the Program apachectl is not written for two apache instances on one server, but normally you dont have to restart them to often  :Wink: 

Hope this will be helpful to you,..

----------

## pi314

this blog entry over here sounds promising:

http://www.digitalsandwich.com/archives/14-PHP5-and-PHP4-Running-on-SAME-apache-server.html

but read it carefully, the method mentioned first seems to be BSD related, but at the end there is some discussion about linking to the correct libraries... maybe I'll give it a try soon.

good luck and please report back if you are successfull

pi

----------

## drax_

Hi, sorry to be a little late, but here we go.

I also needed to run PHP4 and PHP5 alongside each other. I've managed it, and exposed it in other threads, and also on my website.

The way I set it up, is mod_php4 (apache handler) and php5 as FastCGI since php4 was the "testing version" and php5 the definite version. I have combined the use of php CGI's with mod_suexec, which is IMO, alot more secure than mod_php (in a webhosting environnement ie: multiple users using the same server).

This might not be your case (only you or trusted people use the server, not anyone else), and don't forget when PHP is used as a CGI, an external executable is called, and might therefor create more processing overhead, than mod_php would. (I have yet to benchmark both of them  :Smile: 

Anyway, if you're interested I trying my setup, you can read my post/tutorial. The whole tutorial is far from complete, but the PHP section contains the information you are looking for.

Having both mod_php4 and mod_php5 would probably require hacking the source code, and is (IMO) not viable, in an environnment which emerges world on a daily basis (this again, might not be your case).

----------

## SilverOne

Last week I suddenly made the plunge and installed PHP5 along side PHP4

I used a different approach, using two apache daemons to run on different ports.

This has one advantage over the above solution: I do not need to rename files to test them with PHP5

(other than that drax_' solution seems to have more advantages  :Wink:  )

I don't have time to make a nice how-to at the moment, but here is what I did in a nutshell:

(note, it is not for the faint-hearted, and I'm putting it down by memory, so I hope it is correct.  Use the following instructions ONLY on testing machines.  I do not accept responsibility if you mess up your system.  These instructions are by no means guaranteed to work)

- phpinfo() on the current install, and note the compile-time directives to PHP4

- download the php5 source

- "construct" the compile options for php5 using the options used for php4 and the help at './configure --help'

-> Add the following options:

 --with-config-file-path=/etc/php/apache2-php5-shadow 

 --libdir=/usr/lib/php5-shadow 

 --program-suffix=5-shadow

(these will make sure that it doesn't get in the way of the currently installed php4 versions of the cgi, mod_php and cli interpreters, and it's not likely that gentoo's ebuild voor php5 will use these names  :Smile:  )

- make a backup of your system before continuing (as you should always do!!)  (especially apache2.conf + commonapache2.conf / httpd.conf)

- compile and install using 'make' and 'make install'

- recover the changes in httpd.conf by copying the backup over it (the install script "helps" you by changing it)

- make a copy of httpd.conf (or apache2.conf + commonapache.conf) to httpd_php5shadow.conf (or apache2_php5-shadow.conf and commonapache_php5-shadow.conf)

inside the configuration files you just copied change the following settings :

(note: I changed them, and it worked, it might not be the minimum required, I did not check)

 - Listen 80  --> Listen 81  (or another port if preferred)

 - Listen 443  --> Listen 444 (note: I did not test ssl functionality, this might not work)

 (depending on configuration) - change Include conf/commonapache2.conf --> Include conf/commonapache2_php5-shadow.conf

 - Include conf/modules.d/70*.conf --> Include conf/modules.d/71_mod_php5-shadow.conf

 - PidFile /var/run/apache2.pid  --> PidFile /var/run/apache2_php5-shadow.pid

 - ErrorLog logs/error_log  --> ErrorLog logs/error_log_php5-shadow

 - ServerName <name>:80 --> ServerName <name>:81

- Next: make a copy of the current mod_php configuration file and call it 71_mod_php5-shadow.conf

- Edit it to change the loadmodule directive to "LoadModule php5_module    extramodules/libphp5-shadow.so"

- and optionally add the .php5 file extension: "AddType application/x-httpd-php .php5"

- change the ifDefine statement to check for PHP5

- browse through commonapache2_php5-shadow.conf to see wether anything needs changing (I did not change anything)

Now you need to start (and optionally kill) the second apache daemon by hand.  I use:

 - apache2 -f /etc/apache2/conf/apache2.conf.php5-shadow -e debug -DSSL -DPHP5 -X

This will start a single httpd server process, and it will not background, use this to test the configuration

by pointing your browser at: http://www.yourdomainname.tld:81

(or use a different port depending on your choice earlier)

if it all seems to work (call a php file with phpinfo() in it, to check)

you can use this command to launch the httpd service in the background:

(press ctrl+c to quit this server first)

 - apache2 -f /etc/apache2/conf/apache2.conf.php5-shadow -e debug -DSSL -DPHP5

(which is the same command without the -X flag)

If you need to kill it now, you will need to kill each apache process by hand (or risk shutting down the main apache server on port 80) or reboot the entire machine.

I hope this helps someone, if there are any questions / remarks, I'll come back and clarify (and enhance readability of this post  :Smile:  )

NOTE: I'll say it again, also have a look at drax_'s  solution (one post up).  It seems to be cleaner and better suited for most needs.  I'll probably use the same solution later on when I want to force all my sites to default to PHP5  (and allow the users to opt for php4)

(I run a couple of vhosts and I don't want to force PHP5 on anyone yet, my solution is geared towards a testing ground for my vhosts)

----------

## andreask

 *ezekiel61 wrote:*   

> I haven't spent much time on this since I originally posted. I did find an apache project called XAMPP at http://www.apachefriends.org/en. This is a Windows Apache project. However, if you install it they claim to run both PHP4 and PHP5 along with other Apache projects such as Tomcat and Cocoon. I suppose if one were to install this and check out how they setup their htttpd.conf file we could figure this out... as of right now I don't have the time to do it. I'll update if I get any progress.

 

Please note that XAMPP is not meant for production use and should really only be used in a development environment:

 *XAMPP README wrote:*   

> As mentioned before, XAMPP is not meant for production use but only for developers in a development environment. The way XAMPP is configured is to be open as possible and allowing the developer anything he/she wants. For development environments this is great but in a production environment it could be fatal.

 

http://www.apachefriends.org/en/xampp-linux.html#381

----------

## andreask

 *ezekiel61 wrote:*   

> I need to have multiple versions of PHP running for new and old web applications.

 

The latest PHP Packages which have been added to Portage yesterday support PHP4 and PHP5 beeing installed parallel on one Gentoo Box:

from latest GWN: Simultaneous PHP4/PHP5 support in Gentoo

Announcement Posting on gentoo.dev: Packages for mixed PHP4/PHP5 environment added to Portage

Posting from planet.gentoo.org: PHP Overlay Packages Now In Portage

Documentation from Gentoo PHP project page:

Upgrade HOWTO: http://svn.gnqs.org/projects/gentoo-php-overlay/wiki/HowToUpgrade

FAQ: http://svn.gnqs.org/projects/gentoo-php-overlay/wiki/CommonQuestions

Retiring the old packages: http://svn.gnqs.org/projects/gentoo-php-overlay/wiki/RetiringTheOldPackages

 *ezekiel61 wrote:*   

> Can we just emerge both mod_php4 and mod_php5  and add the directives in /etc/conf.d/apache for "-D PHP4 -D PHP5". 

 

You can emerge both, which is quite easy with the new Packages:

```
USE="apache" emerge '=dev-lang/php-4*' '=dev-lang/php-5*'
```

But you cannot use two mod_php's in the same Apache-Server instance (because both export the same symboles). You can use CGI, which is possible, and you can use 2 instances of Apache (start your Apache twice with different configs). Or you can use mod_php4 and php-cgi5... 

But make sure to read the docs mentioned above, many things have changed in PHP support!

----------

