We had a hosting server which ran two instances of HTTPDs: one for administration purposes and one for the websites we host. Recently this server was upgraded from a very old Redhat 8 to Fedora (Core) 7. I have recreated many of the configs, and run into some trouble setting up those two instances of Apache (actually Apache 2.2).
(FYI, the two instances are needed for security and performance reasons: the admin server loads mod_perl and some other big modules, running as a normal user, while the httpd for our users have nobody privileges and it had mod_php and a few other small modules loaded. As the matter of fact I have yet another webserver as a reverse proxy on this machine, but let's not go into that now.)
Anyway, the trouble was that when I tried to shut down one of the servers, it took down the other one as well. I had two separate configurations, different DocumentRoots, PID files, and so on.
Without going into too much details, I have tracked down this problem to two things. First is the init script that comes which Fedora. Line 74, in /etc/init.d/httpd. See here:
stop() {
echo -n $"Stopping $prog: "
killproc -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
Line 74 is this:
killproc -d 10 $httpd
Now this calls killproc as supplied by /etc/rc.d/init.d/functions, and it actually
kills the process by name - at least as fas as I can tell (I am not a BASH guru).
Change this to:
killproc -p $pidfile -d 10
And bingo! Of course you have to make sure $pidfile is set.
The other problem is "mea culpa": I have copied /etc/httpd to another location, and I used a pid file pointing to
run/httpd.pid in both of the servers. Now the "run" directory is actually a symlink to /var/run, so the two pid files overwrote each other! When given another name, everything started working.
Here is a short description on how to create two (or more) instances of the same httpd (Apache) binary running on a Linux (in our case: Fedora) server!
1. You have /etc/httpd as your Apache config dir and /etc/init.d/httpd as your init script for the "original" apache.
2. Make a copy of the dir /etc/httpd. Let's call it now /etc/httpd2
3. Make a copy of the init script /etc/init.d/httpd as /etc/init.d/httpd2
4. Make a copy of /etc/sysconfig/httpd as /etc/sysconfig/httpd2
4. Configure /etc/httpd2/conf/httpd.conf such as
- the ServerRoot points to /etc/httpd2
- PidFile is set to runt/httpd2.pid
- port:IP pairs do not overlap with those set with your "original" httpd configuration
5. Modify /etc/init.d/httpd2 such as
- "killproc -d 10 $httpd" is "killproc -p $httpd" (appears twice in the file!)
- do this in /etc/init.d/httpd, too
- instead of /etc/sysconfig/httpd load /etc/sysconfig/httpd2
6. Change /etc/sysconfig/httpd2 so that it contains:
- OPTIONS='-d /etc/httpd2'
- PIDFILE=/var/run/httpd2.pid
- LOCKFILE=/var/lock/subsys/httpd2
- CONFFILE=/etc/httpd2/conf/httpd.conf
And that's it!
Make sure you first take down Apache (if it's running) before you modify all the config files. Then start the two instances one-by-one.
If the second Apache instance is not starting up, claiming it cannot bind to the port(s), then you have either overlapping ports in your httpd.conf -s, or somehow you are loading wrong configs.
Of course this is for Fedora 7, for Apache 2.2 installed as a binary (RPM) package, so YMMV. Use this at your own risk!