preload preload

Linux Apache httpd init.d Script

It is usually a good practice to install the Apache httpd as the service on the linux server so that it can be added to system startup and does not require any intervention from user to start the Apache httpd server manually on every reboot. Linux servers like (CentOS, RHEL, etc) requires to place the init scripts in the /etc/init.d directory to allow creation of custom services.

Some Apache installation packages like httpd rpm’s or when installed from yum install the Apache httpd as the service whereas when built from the source it doesn’t.

Below the Apache httpd init script which you can copy to your /etc/init.d folder and install the Apache httpd as the service.

# Startup script for the Apache Web Server
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#           HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache2/logs/
# config: /usr/local/apache2/conf/httpd.conf

# Source function library.
. /etc/rc.d/init.d/functions

# See how we were called.
case "$1" in
echo -n "Starting httpd: "
daemon /usr/local/apache2/bin/httpd -DSSL
touch /var/lock/subsys/httpd
echo -n "Shutting down http: "
killproc httpd
rm -f /var/lock/subsys/httpd
rm -f /usr/local/apache2/logs/
status httpd
$0 stop
$0 start
echo -n "Reloading httpd: "
killproc httpd -HUP
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1

exit 0

After copying you can add the httpd service to linux startup using linux chkconfig command.

chkconfig --add httpd

And, you are done!!!

Liked the content? Then why not share with your pals

  • One response to "Linux Apache httpd init.d Script"

  • Sam
    2:12 on June 29th, 2011

    Remember to chmod +x /etc/init.d/httpd as well.

  • Leave a Reply

    * Required
    ** Your Email is never shared