When trying to perform a graceful restart of Apache on CentOS 7.4 using the standard apachectl -k graceful
command, you might encounter this frustrating message:
[root@localhost root]# apachectl -k graceful
Passing arguments to httpd using apachectl is no longer supported.
You can only start/stop/restart httpd using this script.
If you want to pass extra arguments to httpd, edit the
/etc/sysconfig/httpd config file.
This behavior occurs because CentOS/RHEL systems modify the default apachectl
script to work with their service management system. The modified version doesn't support passing the -k
flag directly.
Here are three working solutions:
Method 1: Using systemctl (Recommended)
sudo systemctl reload httpd.service
Or for a full graceful restart:
sudo systemctl graceful httpd.service
Method 2: Direct httpd Command
sudo /usr/sbin/httpd -k graceful
Method 3: Editing sysconfig (Permanent Solution)
Edit the configuration file:
sudo vi /etc/sysconfig/httpd
Add this line:
OPTIONS="-k graceful"
Then restart normally:
sudo systemctl restart httpd
Check if the restart was successful:
sudo apachectl status
sudo systemctl status httpd
Or check the process IDs:
ps aux | grep httpd
- Graceful restart maintains existing connections while loading new configuration
- Use
reload
for configuration changes,graceful
for both config and code changes - Older Apache versions might need different approaches
If you encounter issues:
sudo apachectl configtest
sudo journalctl -xe
sudo tail -f /var/log/httpd/error_log
When attempting to gracefully restart Apache on CentOS 7.4 using the documented apachectl -k graceful
command, you'll encounter this frustrating message:
[root@localhost root]# apachectl -k graceful
Passing arguments to httpd using apachectl is no longer supported.
You can only start/stop/restart httpd using this script.
If you want to pass extra arguments to httpd, edit the
/etc/sysconfig/httpd config file.
CentOS 7 uses systemd for service management, which changes how we interact with Apache. The traditional apachectl
method no longer accepts direct arguments in this configuration.
Here are three reliable methods to perform a graceful restart on CentOS 7:
Method 1: Using systemctl
sudo systemctl reload httpd.service
This sends a SIGHUP signal to Apache, triggering a graceful restart where existing connections complete before workers restart.
Method 2: Direct httpd Command
sudo /usr/sbin/httpd -k graceful
This bypasses apachectl and directly calls httpd with the graceful parameter.
Method 3: Editing sysconfig (Permanent Solution)
Edit /etc/sysconfig/httpd
:
# Add this line to OPTIONS
OPTIONS="-k graceful"
Then restart normally:
sudo systemctl restart httpd
Check if your restart was successful:
sudo apachectl status
sudo systemctl status httpd
sudo tail -f /var/log/httpd/error_log
Graceful restarts prevent dropped connections during configuration changes or updates. This is particularly crucial for:
- E-commerce sites processing transactions
- API endpoints handling long-running requests
- Websockets maintaining persistent connections
If you encounter problems after a graceful restart:
# Check for syntax errors first
sudo apachectl configtest
# Verify SELinux context
sudo ls -Z /etc/httpd
# Examine open files
sudo lsof -i :80