I have edited the variable AllowOverride for one of my websites in sites-enabled directory. How do I reload the new configuration without restarting apache? Is it possible?
6 Answers
It should be possible using the command
sudo /etc/init.d/apache2 reload
-
19I am pretty sure this is not correct. Looking in the init.d-script of an Ubuntu server, reload refers to the graceful restart. This means that reload is in fact a restart, but gracefully. My opinion is that apache can't be reloaded without interrupting the service. Mar 3, 2017 at 12:54
-
8Aruman's answer is the correct one. Most Apache init scripts send SIGHUP which is equivalent to 'apachectl restart', which the OP specifically asked to avoid. Other Apache init scripts send SIGUSR1 which is equivalent to 'apachectl graceful', which is also a restart, but done more gracefully, and is what Aruman's answer provides. May 4, 2017 at 15:13
-
@SteffenNielsen I think you're right... Some will be fine with using a load balancer, disabling the one to be restarted, restarting, dealing with db versioning, then doing the same for the other apache server/container. K8s does away with some of these issues.– Ray FossJul 12, 2018 at 15:45
-
1Okay, here is what happens, the main apache2 process doesn't change, but the children or workers (I don't know the right terminology) all restart, those PIDs do in fact change. Mar 13, 2019 at 0:43
-
1And I think graceful in this case just means that those children workers finish serving their requests before being killed and respawned. Mar 13, 2019 at 1:51
Do
apachectl -k graceful
Check this link for more information : http://www.electrictoolbox.com/article/apache/restart-apache/
-
25This will restart the Apache httpd daemon, which the question specifically asked to avoid.– cs01Apr 20, 2015 at 21:25
-
9@cs01 Where do you read that the httpd daemon will be restarted? Everything I read on the link provided in the answer says things like
apachectl graceful: Gracefully restarts the Apache daemon by sending it a SIGUSR1. If the daemon is not running, it is started. This differs from a normal restart in that currently open connections are not aborted.
Feb 18, 2017 at 1:07 -
5The first sentence of the documentation you posted says just that, does it not?– cs01Feb 18, 2017 at 4:50
-
3@cs01 You need to understand why they are worried about a restart. That is not specified, but my guess is they don't want connections aborted, rather than a restart in itself. A graceful restart will do this fine in most cases. If there are long lived connections this maybe an issue though. You also need a good definition of restart as well, as all the graceful restart does is reinitialise the parent process ie the pid doesn't change, where as a normal restart tears down the whole process tree, and spawns a new one. Therefore Tyler Collier answer is perfectly legitimate.– kradMar 1, 2017 at 12:39
-
1
If you are using Ubuntu server, you can use systemctl
systemctl reload apache2
-
On ubuntu 18 (at least) this is an alias to
/usr/sbin/apachectl graceful
– Will SFeb 16, 2021 at 11:37
Updated for Apache 2.4, for non-systemd (e.g., CentOS 6.x, Amazon Linux AMI) and for systemd (e.g., CentOS 7.x):
There are two ways of having the apache process reload the configuration, depending on what you want done with its current threads, either advise to exit when idle, or killing them directly.
Note that Apache recommends using apachectl -k
as the command, and for systemd, the command is replaced by httpd -k
apachectl -k graceful
or httpd -k graceful
Apache will advise its threads to exit when idle, and then apache reloads the configuration (it doesn't exit itself), this means statistics are not reset.
apachectl -k restart
or httpd -k restart
This is similar to stop, in that the process kills off its threads, but then the process reloads the configuration file, rather than killing itself.
-
1apache 2.4.39 (win) does not support
httpd -k graceful
onlyhttpd -k restart
:httpd /?
=>-k restart : tell running Apache to do a graceful restart
Apr 4, 2019 at 9:36
Late answer here, but if you search /etc/init.d/apache2
for 'reload', you'll find something like this:
do_reload() {
if apache_conftest; then
if ! pidofproc -p $PIDFILE "$DAEMON" > /dev/null 2>&1 ; then
APACHE2_INIT_MESSAGE="Apache2 is not running"
return 2
fi
$APACHE2CTL graceful > /dev/null 2>&1
return $?
else
APACHE2_INIT_MESSAGE="The apache2$DIR_SUFFIX configtest failed. Not doing anything."
return 2
fi
}
Basically, what the answers that suggest using init.d, systemctl, etc are invoking is a thin wrapper that says:
- check the apache config
- if it's good, run
apachectl graceful
(swallowing the output, and forwarding the exit code)
This suggests that @Aruman's answer is also correct, provided you are confident there are no errors in your configuration or have already run apachctl configtest
manually.
The apache documentation also supplies the same command for a graceful restart (apachectl -k graceful
), and some more color on the behavior thereof.
apachectl
in CentOs orapache2
in Ubuntu). But the concern is to do without restarting. All restart, but the graceful (SIGUSR1
) solutions wait for no open connections to be broken.