Starting and Stopping Apache Automatically on Red Hat Linux

by Nathan Wallace (Oct 25, 1999)
and John Brett (Dec 4, 2000)


After you've installed Apache it's often a good and convenient idea to make it start and stop automatically with the machine. These instructions are specific for Red Hat Linux and it's variants since different Linux distributions tend to layout the start up scripts differently.

The example script is based on my Apache installation instructions.

Starting and Stopping Apache Automatically

  1. Firstly, log in as root
        su root

  2. The next thing we need to do is create a start up and shutdown script for Apache. I use a slightly modified version of the standard Red Hat one. You need to create or modify this script located at:
    Here is a copy (removed) of the start up script I use for my installation. You can just change the PID file (PIDFILE) and httpd binary (BINFILE) locations in that script if you set up your Apache differently.

  3. We need to make this file executable:
        cd /etc/rc.d/init.d
        chmod 755 httpd

  4. Now we need to link to this script, causing it to be run on automatically on server shutdown. I'm not sure if all of these are needed, here I'm just copying the Red Hat solution. If these links already exist then you do not need to change them so long as they point to the httpd file we just created.
        cd /etc/rc.d/rc0.d
        ln -s ../init.d/httpd K15httpd
        cd /etc/rc.d/rc6.d
        ln -s ../init.d/httpd K15httpd

  5. Now add a link to the script to be run when the server starts:
        cd /etc/rc.d/rc3.d
        ln -s ../init.d/httpd S15httpd
        cd /etc/rc.d/rc5.d
        ln -s ../init.d/httpd S15httpd

  6. You can check if everything worked as expected by rebooting your machine (after saving everything):
        shutdown -r now