Apache stop and start

Share on:

Starting Apache Server

In Unix httpd program run in demon that execute continuously to serve the request. This program will initiate many child process based on configuration, eg., for logFile rotation one process. Usually this program runs on Port 80 ( It is possible to configure different port this based on your need). In unix you cant bind this port with normal user privileges, hence its recommended to run with root user.

To invoke httpd program, we use apachectl script. It is editable script and you can configure customised httpd configuration file also in this script. So apachectl script initiate httpd process based on configured httpd configuration file.

PREFIX/bin/apachectl –f PREFIX/conf/httpd.conf start

Eg., /usr/local/apache/bin/apachectl –f /usr/local/apache/conf/httpd.conf start

Common Errors in startup

  • Unable to bind to port 80 – Please check if any instance is running with port 80
  • Fatal error while startup – Please check the user which you trying to start has proper privileges or not.

Starting Apache at server 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) with start , stop , restart arguments based on your need.

Stopping and restarting apache webserver

When you start apache it creates pid file with parent process id eg., /usr/local/apache2/logs/httpd.pid. So to stop the process just kill the parent process which will kills the child process as well.

kill -9 ‘cat /usr/local/apache2/logs/httpd.pid‘

Stop server immediately

apachectl -k stop

This command will stop apache immediately including child process

Graceful restart

apachectl –k graceful

Graceful signal causes the parent process to advise the children to exit after their current request (or to exit immediately if they’re not serving anything). The parent re-reads its configuration files and re-opens its log files. As each child dies off the parent replaces it with a child from the new generation of the configuration, which begins serving new requests immediately.

Restart immediately

apachectl –k restart

Restart signal to the parent causes it to kill off its children, but the parent doesn’t exit. It re-reads its configuration files, and re-opens any log files. Then it spawns a new set of children and continues serving hits.

Graceful Stop

apachectl -k graceful-stop

Graceful-stop signal causes the parent process to advise the children to exit after their current request (or to exit immediately if they’re not serving anything). Parent will wait for child process to stop until gracefulshutdowntimeout period and it kill all its child. Delete the pid file also.

comments powered by Disqus