Every tired to change apache config from a program and then wondered how to restart apache. Here’s a solution. APACHECTL.
When you do restart of apache, it will kill all the current sessions. But with apachectl you have option to restart the server gracefully without killing any previous sessions. This way all further connections will take up the new settings.
I’ve been doing this for a small little experiment, I wanted to add dynamic subdomains, So I had to edit the apache host httpd.conf files and we all know we have to restart the server after any config file is changed. So here’s an alternative. Change the config files from your PHP or CGI etc, and then call this apachectl.
The command is : apachectl graceful
For Ubuntu and debian system the command would be : apache2ctl graceful
Here are some quick references from Apache’s official page:
- Start the Apache
httpddaemon. Gives an error if it is already running. This is equivalent to
apachectl -k start.
- Stops the Apache
httpddaemon. This is equivalent to
apachectl -k stop.
- Restarts the Apache
httpddaemon. If the daemon is not running, it is started. This command automatically checks the configuration files as in
configtestbefore initiating the restart to make sure the daemon doesn’t die. This is equivalent to
apachectl -k restart.
- Displays a full status report from
mod_status. For this to work, you need to have
mod_statusenabled on your server and a text-based browser such as
lynxavailable on your system. The URL used to access the status report can be set by editing the
STATUSURLvariable in the script.
- Displays a brief status report. Similar to the
fullstatusoption, except that the list of requests currently being served is omitted.
- Gracefully restarts the Apache
httpddaemon. If the daemon is not running, it is started. This differs from a normal restart in that currently open connections are not aborted. A side effect is that old log files will not be closed immediately. This means that if used in a log rotation script, a substantial delay may be necessary to ensure that the old log files are closed before processing them. This command automatically checks the configuration files as in
configtestbefore initiating the restart to make sure Apache doesn’t die. This is equivalent to
apachectl -k graceful.
- Run a configuration file syntax test. It parses the configuration files and either reports
Syntax Okor detailed information about the particular syntax error. This is equivalent to
The following additional option is available, but deprecated.
- This is equivalent to
apachectl -k start -DS