Skip to content

Testing the Apache config on cPanel before you restart anything

A short discipline that prevents 90 percent of outages caused by Apache restarts on cPanel — using apachectl -t, configtest scripts, and userdata cache validation before touching the running service.

Most “Apache will not start after I edited a config” incidents are preventable by typing apachectl -t first. On cPanel the picture is one layer thicker because the live httpd.conf is regenerated from /var/cpanel/userdata/ — so a config that looks fine on disk may fail to regenerate after the next userdata change. The discipline is to test both the rendered config and the userdata cache before any restart.

What’s happening

cPanel’s Apache config pipeline has three stages: the userdata files under /var/cpanel/userdata/<user>/<domain>, the include editor snippets under /etc/apache2/conf.d/userdata/, and the rendered /etc/apache2/conf/httpd.conf. apachectl -t only tests the third. If you edited a userdata YAML by hand or pushed a templating change, the syntax is not validated until the next /scripts/rebuildhttpdconf actually runs — which may be triggered automatically by something else hours later, when you are not at the console.

How to verify

Run all three checks before any restart:

apachectl -t
/scripts/verify_vhost_includes
/scripts/rebuildhttpdconf --verify
apachectl -t -D DUMP_VHOSTS | head -40
apachectl -t -D DUMP_INCLUDES | head -20

apachectl -t validates the running config. /scripts/verify_vhost_includes validates the Include Editor snippets. /scripts/rebuildhttpdconf --verify regenerates into a temporary file and tests it without overwriting the live one.

The fix

  1. After any edit to /etc/apache2/conf/httpd.conf, an Include Editor change, or a WHMAPI1 modify_vhost call, run the three commands above in order. If any fails, do not proceed.
  2. If apachectl -t fails with a syntax error, the line and column are usually exact — fix at source, do not reload.
  3. If /scripts/rebuildhttpdconf --verify fails but apachectl -t passes, the live config is currently fine but the next regeneration will fail. Find the offending userdata file: grep -rl "syntax-error-token" /var/cpanel/userdata/. Fix at source.
  4. Use apachectl graceful for normal reloads — it sends SIGUSR1, allowing in-flight requests to complete on the old config while new connections use the new one. apachectl restart interrupts in-flight requests.
  5. If a restart is required (rare — module load/unload, MPM change), schedule it. Even apachectl graceful-stop followed by start is preferable to restart when you control the window.
  6. Bake the three-command check into any change-management script that touches Apache config. The five seconds it takes is cheaper than the five minutes of explaining why every site on the box returned 500.

For environments where every Apache change goes through change management, Stack Harbor runs config-test gates ahead of every reload as part of cPanel server management.