Multiple Apache instances on Gentoo box

I’ve started looking how to enable both PHP4 and PHP5 on our (relatively) new dev box running Gentoo. The box is already running PHP4 so the task was to add PHP5 support as well.

The official guide is rich in options you can use to achieve this. I didn’t want any CGI since we use PHP vhost configurations extensively and I didn’t want to deal with suPHP as well. Since it is a dev box, it is totally OK to have two instances with similar configurations running on two different ports. Unfortunately, it is the part of the official docs that is not as complete as other parts and not working as advertised. So, here’s a mental note (for me) and perhaps a few hour saver for others.

First of all, just copy /etc/init.d/apache2 to /etc/init.d/apache2-php5. There’s no need to change anything in this file

$ diff /etc/init.d/apache2 /etc/init.d/apache2-php5
$

since it will look to /etc/conf.d/apache2-php5 for default configuration and that is where we will make our changes. So, copy /etc/conf.d/apache2 to /etc/conf.d/apache2-php5

Here’s a list of changes that works for me

$ diff /etc/conf.d/apache2 /etc/conf.d/apache2-php5

1c1
< # /etc/conf.d/apache2: config file for /etc/init.d/apache2
---
> # /etc/conf.d/apache2-php5: config file for /etc/init.d/apache2-php5
20c20
< APACHE2_OPTS="-D DEFAULT_VHOST -D PHP4"
---
> APACHE2_OPTS="-D DEFAULT_VHOST -D PHP5"
34c34
< #CONFIGFILE=/etc/apache2/httpd.conf
---
> CONFIGFILE=/etc/apache2/httpd-php5.conf

Basically, it uses PHP 5 and points to other httpd.conf file. So the next step is to copy /etc/apache2/httpd.conf to /etc/apache2/httpd-php5.conf and make some changes (port numbers, files used, etc). Here’s an example

$ diff /etc/apache2/httpd.conf /etc/apache2/httpd-php5.conf

88c88
< PidFile "/var/run/apache2.pid"
---
> PidFile "/var/run/apache2-php5.pid"
214c213
< Listen 80
---
> Listen 8000
587c586
< ErrorLog logs/error_log
---
> ErrorLog logs/error-php5_log
617c616
< CustomLog logs/access_log common
---
> CustomLog logs/access-php5_log common

Finally, you’ll have to modify your existing virtual host configurations to include a conf for the new port (8000 in this case). So for the default vhost configuration located in /etc/apache2/vhosts.d/00_default_vhost.conf you should add this line

NameVirtualHost *:8000


and make another copy of default configuration of port 80

<VirtualHost *:80>
</VirtualHost>


for port 8000

<VirtualHost *:8000>
</VirtualHost>


Start these two Apache instances

/etc/init.d/apache2 start
/etc/init.d/apache2-php5 start


and that’s all folks!

Leave a comment

Your email address will not be published. Required fields are marked *