Yaniv's Web Corner

Multi-Apachectl

By Yaniv Yemini

Description

Httpd-Multi is a set of scripts that will help you manage multiple instances of Apache 2.2.
It is distributed under the Apache 2.0 license.

  • httpd-multi - is a script that replaces Apache's default init.d script (httpd), and which will automatically start and stop all Apache instances.
  • apachectl-multi - is a replacement script for apachectl that is bundled with Apache. It will allow you to control each Apache instance separately.

The scripts are now hosted on Github: GitHub httpd-multi

How to use the scripts

To control an Apache instance, use apachectl-multi, just like you would use the original apachectl that comes with Apache, but with the server instance's root directory name as the first argument:

apachectl-multi www start

In this example, the first argument "www" is the Apache instance's ServerRoot directory name (see How to Install the scripts for an example of how to set up the server instances).

The second argument for apachectl-multi is one of the control commands that you would normally use with Apache's apachectl:

  • start - start httpd
  • stop - stop httpd
  • restart - restart httpd if running by sending a SIGHUP or start if not running
  • fullstatus - dump a full status screen (requires lynx and mod_status enabled)
  • status - dump a short status screen (requires lynx and mod_status enabled)
  • graceful - do a graceful restart by sending a SIGUSR1 or start if not running
  • graceful-stop - do a graceful stop of the server.
  • configtest - do a configuration syntax test
  • help - display help

How to Install the scripts

Following are instructions how to use the scripts.

Create ServerRoot directories

The first step is to create an Apache ServerRoot for each instance of Apache under one base directory. In this example, we will use /usr/local/apache/sites as the base directory:

/usr/local/apache/sites
                     www/
                     blog/
                     forum/
                    

Each subdirectory under /usr/local/apache/sites is an Apache ServerRoot directory with the following structure:

  • conf - configuration dir, with http.conf.
  • logs - server logs dir
  • modules - a symbolic link to the Apache's installation modules directory.

Configure httpd.conf

Configure each instance httpd.conf so paths to the logs, LoadModule, DocumentRoot and other directives will point to the correct locations.

Install Multi-Apachectl scripts

First, we'll install the apachectl-multi script, which controls the starting and stopping of Apache.
  1. Download httpd-multi from Github:
    git clone https://github.com/yanivyam/httpd-multi.git
  2. Copy the file apachectl-multi into the bin directory of your Apache installation. It should be placed under the same parent directory as Apache's original apachectl script.

    cp apachectl-multi /usr/local/apache/bin

  3. Copy httpd-multi to your init.d directory (the exact location depends on your Linux/Unix distribution):

    cp httpd-multi /etc/init.d/

  4. Edit the following in apachectl-multi:
    HTTPD - set to the path of Apache's binary (httpd).
    APACHE_INSTANCES_BASEDIR - set it to the base directory (see "Create ServerRoot directories" above).

The next step is to setup httpd-multi, which is the init.d script that is responsible of starting and stopping Apache instanaces during boot and shutdown of the server.

  1. Setup httpd-multi to run during boot and shutdown of the server.

    Usually, this involves copying httpd-multi to your init.d directory, and then use chkconfig utility tell the system when to call the script during boot and shutdown processes.

  2. Edit the following in httpd-multi to reflect the paths on your system:
    httpd - the path to httpd
    pidfile - the path to Apache's PID (process id) file.
    APACHE_INSTANCES_BASEDIR - set it to the base directory (see "Create ServerRoot directories" above).

Download

You can browse the code on GitHub: https://github.com/yanivyam/httpd-multi.

Or, download the latest version of httpd-multi for Apache 2.2 from GitHub:

git clone https://github.com/yanivyam/httpd-multi.git

Comments and feedback

Name:
EMail:
Message:
 

Please type in the exact letters from the image above:

 
© Yaniv Yemini, 1998-2010