Installation

Starting Apache Automatically

Starting Apache Automatically

by Leah Bergman -
Number of replies: 5
We have an issue when we restart the server...  Apache does not start automatically.  Is there a way that we can set Apache to start automatically?  We're usually forced to enter this after a reboot: 

sudo ./apachectl restart

Any suggestions would be very appreciated.  Thanks!

In reply to Leah Bergman

Re: Starting Apache Automatically

by Arnold Pizer -
Hi Leah,

Hopefully a unix expert (which I am certainly not) will answer this. The apache documentation ( http://httpd.apache.org/docs/2.2/invoking.html ) gives some very general advice:

Starting at Boot-Time

If you want your server to continue running after a system reboot, you should add a call to apachectl to your system startup files (typically rc.local or a file in an rc.N directory). This will start Apache as root. Before doing this ensure that your server is properly configured for security and access restrictions.

The apachectl script is designed to act like a standard SysV init script; it can take the arguments start, restart, and stop and translate them into the appropriate signals to httpd. So you can often simply link apachectl into the appropriate init directory. But be sure to check the exact requirements of your system.

The rc.local file and the rc directories are usually in the /etc/ directory. You might try searching for documentation on starting daemons at boot up for your specific operating system.

Arnie

In reply to Arnold Pizer

Re: Starting Apache Automatically

by Gavin LaRose -
Hi Leah,

In case you haven't already gotten this fixed: in most Unix environments I've worked in, startup scripts for system services are located in /etc/init.d and then linked to the appropriate /etc/rcN.d or /etc/rc.d/rcN.d directory. Local initialization is done in the file /etc/rc.local. Scripts in the rcN.d directories that begin with the letter S are run when the system enters run level N to start services, and those that begin with the letter K are run to kill services. Most Unix servers will be running in run level 3 or run level 5.

On my RedHat servers we use a start script equivalent to apachectl that's called httpd; this is located in /etc/init.d. Then in /etc/rc3.d, /etc/rc4.d and /etc/rc5.d there are symbolic links pointing back to this that start apache. Each of these is called S87httpd (the number just controls the order in which the scripts are run).

Thus one way to ensure that apache starts after a system reboot is to copy the apachectl script to /etc/init.d, e.g.,
     # cp apachectl /etc/init.d/apache 
and then make symbolic links in the appropriate rc directories, e.g.,
     # cd /etc/rc3.d; ln -s ../init.d/apache ./S99apache
# cd ../rc4.d; ln -s ../init.d/apache ./S99apache
# cd ../rc5.d; ln -s ../init.d/apache ./S99apache
(on some systems, it may be necessary to change the above to cd /etc/rc.d/rc3.d and the link command to ln -s ../../init.d/apache ./S99apache). I arbitrarily picked S99 so that apache would then start at the end of the process.

Alternately, apache could be called a local service and run from /etc/rc.local by adding a line at the end of that file to start it, e.g., /path/to/apachectl start.

I hope that's useful,
Gavin
In reply to Leah Bergman

Re: Starting Apache Automatically

by Sam Hathaway -
Hi Leah,

Gavin's tutorial is correct for the most part, although I would symlink apachectl to /etc/init.d/apache rather than making a copy.

What OS/distribution are you using? Did you install Apache from a package, or manually? The reason I ask is that most Linux distributions provide an initscript in /etc/init.d and symlinks in /etc/rc?.d by default when you install Apache from a package.

Probably the easiest way to get Apache to start at boot is to add "apachectl start" to the script /etc/rc.local or /etc/rc.boot (whichever your OS has).
-sam

In reply to Sam Hathaway

Re: Starting Apache Automatically

by Arnold Pizer -
Specifically for SUSE 10.2, which is a system on which Apache2 at least has to be installed manually, do the following (taken from http://devel.webwork.rochester.edu/twiki/bin/view/Webwork/InstallationManualV2pt3forSuSE10pt2#Apache_2_and_mod_perl)

Now set up things so that Apache starts automatically at boot up.

# cd /etc/init.d
# cp boot.local boot.local.bak1
# kwrite boot.local
and add the line
/usr/local/apache2/bin/apachectl start
to the end of the file. Then save the file and quit.
In reply to Leah Bergman

Re: Starting Apache Automatically

by Eric Stroyan -
For FreeBSD edit /etc/rc.conf to include the line
apache_enable="YES"
to automatically start apache at startup.
To start mysql at startup add (also to /etc/rc.conf)
mysql_enable="YES"