Linux – Can RHEL 4 have two instances of apache httpd running using two different config files

apache-2.2httpdhttpd.conflinuxredhat

We have a Red Hat Enterprise Linux 4 instance running Apache on the default port. We want to add a second Apache instance that we can restart completely separate from the first instance. Can we do this?

Perhaps is there another easy-to-maintain web server that can run very simple PHP scripts on a non-standard port? We want to be able to trigger a php script remotely without using the default instance of Apache running on the RHEL server. Any ideas?

Best Answer

In a typical environment, you can create a copy of httpd.conf and then modify the following properties on the new file.


# pid file
PidFile run/httpd.pid

# http listen port
Listen 80

# log files
ErrorLog logs/error_log
CustomLog logs/access_log combined

# server name
ServerName default_host_name

# document root for the default site
DocumentRoot "/var/www/html"

And depending on your implementation you may need to modify additional properties like LockFile (if you are running on a NFS)

And as always you will have to customize the virtual host definitions if you use them.

Controlling the new instance

Say for example if the name of the newly copied file is /etc/httpd/conf/instance1.conf, then you can start this new instance using the following command

httpd -f /etc/httpd/conf/instance1.conf -k start

Another useful option of the httpd command will be the -t option to test the configuration file for errors.

httpd -f /etc/httpd/conf/instance1.conf -t

See 'man 8 httpd' for more information on how to use httpd command.

And as others hinted, you could should create a separate init script to help you manage this instance. The stock RH /etc/init.d/httpd script should act as a starting point.