Yes, you can gracefully restart the Apache v1.x or v2.x httpd daemon under Linux or Unix like operating systems. You can send the following signals to httpd to start, restart, reload, or stop the server:
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | apachectl/service command |
Time | N/A |
- start
- restart
- graceful
- stop
- graceful-stop
A note about graceful Apache webserver restart
You need to send USR1 signal to the apache server:
This (USR1) 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.
Command syntax to gracefully restart the Apache 1.x/2.x after changing config file
Type the following command as a root user:
apachectl -k graceful
OR
apache2ctl -k graceful
You can also use Linux distro specific Sys V init script as follows to gracefully reload the server. The following example works on RHEL/CentOS Linux and friends only:
/etc/init.d/httpd graceful
OR
/sbin/service httpd graceful
Debian / Ubuntu Linux and friends use the following syntax:
/etc/init.d/apache2 reload
Monitoring apache progress
After you have signaled Apache 2, you can read apache error_log file about its progress by issuing the following tail command:
## For RHEL / CentOS and friends ## tail -f /var/log/httpd/error_log ## For Debian / Ubuntu and friends ## tail -f /var/log/apache2/error.log ## FreeBSD Unix ## tail -f /var/log/httpd-error.log
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 3 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Thanks for the helpful information. How would the graceful restart work if I have a password protected SSL Certificate and must type in a password every time I restart Apache?
I would suggest checking the integrity of the modified config file before issuing the graceful restart. Without checking, your HTTPD server could stop running if it tries to load a config file with a syntax error.
apachectl configtest
then
apachectl graceful (The -k isn’t necessary)
how we can do the same in Windows ?