Restarting Apache with Cron
Use systemctl restart apache2 (or httpd) in root's crontab with the full path to systemctl. For zero-downtime, prefer apachectl graceful, which finishes in-flight requests before reloading. Restarting a web server needs root.
The crontab line (root)
sudo crontab -e, then:
0 4 * * * /bin/systemctl restart apache2
Use httpd instead of apache2 on RHEL/CentOS. The full path to systemctl is needed because cron's PATH is minimal.
Prefer a graceful reload
To avoid dropping live requests: 0 4 * * * /usr/sbin/apachectl graceful. It reloads config and workers without a hard stop.
Non-root with sudo
Add a NOPASSWD sudoers rule for the exact command, then: 0 4 * * * /usr/bin/sudo /bin/systemctl restart apache2.
FAQ
How do I restart Apache with cron?
In root's crontab: 0 4 * * * /bin/systemctl restart apache2 (or httpd on RHEL). Use the full systemctl path.
How do I reload Apache without downtime in cron?
Use apachectl graceful: 0 4 * * * /usr/sbin/apachectl graceful. It finishes in-flight requests before reloading.
Why does restarting Apache from cron need root?
Binding to port 80/443 and controlling the service require root, so put the job in root's crontab or use a NOPASSWD sudo rule.