Skip to content

apachectl graceful vs restart: reload Apache safely

apachectl graceful reloads Apache without refusing connections. See when it is enough on cPanel, and the order that restarts PHP-FPM without 502 errors.

apachectl graceful reloads Apache’s configuration without cutting anyone off. Run apachectl configtest first, and only when it answers Syntax OK, run apachectl graceful. That pair is the right answer for almost every Apache change on a cPanel server with EasyApache 4. A graceful restart asks each child process to finish the request it is serving and then exit. The parent process, which holds the listening sockets on ports 80 and 443, keeps running, so no visitor gets a refused connection. apachectl restart also keeps the parent, but it kills every child at once, so responses in flight are cut off. A graceful has limits that matter in practice. It lasts as long as your slowest running request, so a 300-second PHP job means a 300-second graceful. It does not reliably pick up a changed Listen directive. And it does nothing for PHP-FPM, which restarts separately; doing the two in the wrong order is how a routine change turns into a wall of 502 errors.

What you’ll accomplish

  • Apply a vhost, .htaccess, TLS or module change with no in-flight request dropped and no connection refused.
  • Tell apart the three restart modes — graceful, restart, and a real stop/start — and pick the cheapest one that actually works.
  • Recognise the short list of changes that genuinely need a full stop and start, and stop paying for a full restart on the many that do not.
  • Sequence an Apache plus PHP-FPM change so requests never arrive at a pool that is not listening yet.
  • Prove afterwards, with evidence rather than optimism, that the new config is live and the old workers are gone.

Prerequisites

Root or a sudo-capable account on a cPanel/WHM server running EasyApache 4. Apache lives at /usr/sbin/httpd, its configuration root is /etc/apache2/conf/httpd.conf, and drop-in files are under /etc/apache2/conf.d/. Know which MPM you run before you touch anything — the behaviour under load differs, and if you are unsure which one you should be running, start with Apache MPM: event vs prefork.

If you are not on cPanel, the same signals apply but the wrappers do not. On RHEL-family systems without cPanel the service is httpd and systemctl reload httpd normally maps to a graceful; on Debian and Ubuntu the binary is apache2, the control script is apache2ctl, and the config lives in /etc/apache2/apache2.conf with sites-enabled/. Verify rather than assume what your unit file does:

systemctl cat httpd | grep -E 'ExecStart|ExecReload'
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful

That ExecReload line is the whole reason systemctl reload httpd is safe and systemctl restart httpd is not.

How it works

Apache runs one parent process as root and a pool of children as the web user. The parent binds the listening sockets at startup and holds them for the life of the process; the children accept connections from those sockets and serve requests. Every restart mode is a variation on what happens to the children, and on whether the parent survives.

apachectl graceful sends SIGUSR1. The parent re-reads its configuration, re-opens its log files, and advises each child to exit after its current request — immediately if it is idle. As each old child dies, the parent replaces it with a child from the new generation, which serves new requests right away. Old and new workers coexist for a while. The parent never exits, so the sockets never close.

apachectl restart sends SIGHUP. The parent still survives and still keeps the sockets, but the children are killed at once, exactly as a TERM would. Connections are not refused, but every response in flight is cut off mid-stream and the client sees a reset. It is faster than a graceful and strictly worse for users, which is why it is rarely the right choice.

A real stop and start — systemctl restart httpd, or apachectl stop followed by apachectl start — is the only mode where the parent exits and the ports are actually released. That is the window where new connections get refused, and it is also the only way to reliably change what Apache is bound to.

Comparison of apachectl graceful, apachectl restart and a full stop and start across sockets, in-flight requests, duration and Listen changes

One detail worth internalising: all three modes run a configuration syntax check before anything is signalled. If the check fails, Apache refuses to restart and keeps serving the old configuration. That is a safety feature, but it means a broken change looks like a no-op unless you read the output.

Step-by-step

  1. Confirm which MPM you are on, because it decides how long a graceful takes.

    httpd -V | head -4
    Server version: Apache/2.4.62 (cPanel)
    Server MPM:     event
      threaded:     yes (fixed thread count)
        forked:     yes (variable process count)

    With prefork, one child equals one process serving one request, so children drain one at a time. With worker or event, one child holds many threads, and that whole process stays alive until every one of its threads has finished. A single 300-second PHP request therefore pins an entire old child and everything running inside it.

  2. Test the configuration before you signal anything. This is not optional politeness; it is the step that tells you whether your change is even syntactically loadable.

    apachectl configtest
    Syntax OK

    A failure looks like this, and no restart of any kind will happen until you fix it:

    AH00526: Syntax error on line 3 of /etc/apache2/conf.d/includes/post_virtualhost_global.conf:
    Invalid command 'ProxyPas', perhaps misspelled or defined by a module not included in the server configuration
    Action 'configtest' failed.
    The Apache error log may have more information.
  3. Reload gracefully. A successful graceful prints nothing at all and returns to the prompt.

    apachectl graceful

    Silence is the success signal. If you want a status line instead, systemctl reload httpd does the same thing through systemd on a stock EA4 unit.

  4. Watch the old generation drain. The parent has already accepted the new config; what remains is old children finishing their work.

    ps -eo pid,etimes,cmd --sort=etimes | grep '[h]ttpd' | head -6
        2851423       4 /usr/sbin/httpd -k start
        2851424       4 /usr/sbin/httpd -k start
        2851290     612 /usr/sbin/httpd -k start
           1841  984213 /usr/sbin/httpd -k start

    The etimes column is age in seconds. The very old one is the parent. Anything else still showing a large age a minute after the graceful is an old child holding a long request.

  5. Use a full restart only for the short list. Changing a Listen directive, binding a new IP or port, swapping the MPM, or upgrading the httpd binary all need the parent to exit. On cPanel, use the wrapper rather than raw systemd so the service manager stays in agreement with reality:

    /scripts/restartsrv_httpd

    It prints a progress line while it waits and finishes with a service-check summary naming the PID it ended up with. Confirm the bind independently:

    ss -ltnp | grep ':80 '
    LISTEN 0      511          0.0.0.0:80        0.0.0.0:*    users:(("httpd",pid=1841,fd=4))
  6. Handle PHP-FPM as its own service, in the right order. Apache on EA4 hands PHP requests to per-domain FPM pools over a socket, so an Apache graceful does nothing to PHP and an FPM restart does nothing to Apache. If a change touches both, reload FPM first so the pools are already listening when Apache starts routing to them.

    /scripts/restartsrv_apache_php_fpm
    apachectl configtest && apachectl graceful

    Verify the pool came back before you move on:

    systemctl is-active ea-php82-php-fpm
    active

    The proxy mechanics behind this are covered in Apache and PHP-FPM over a proxy handler.

Decision table mapping each kind of Apache change to graceful, a full restart, or a separate PHP-FPM reload

Validate it works

Prove it rather than assume it. Open a second shell and start a request loop against a real vhost before you run the graceful, then run the change in the first shell:

while true; do curl -s -o /dev/null -w '%{http_code} ' https://example.com/; sleep 0.2; done
200 200 200 200 200 200 200 200 200 200 200 200

An unbroken run of 200 across the graceful is your evidence. A 000 means curl could not complete the connection at all, which is what a full stop and start looks like from the outside. Then confirm the new configuration is genuinely live rather than merely on disk:

httpd -S 2>&1 | grep -c 'namevhost'
apachectl -M | wc -l

Both numbers should reflect the vhost or module you just added. Finally, check that the old generation is gone. Re-run the ps command from step 4: every child should now be younger than the graceful, with only the long-lived parent above it. If a child is still older than the reload several minutes later, it is stuck on a request, and step 1 of the troubleshooting list applies.

Troubleshooting

The graceful appears to hang and old workers never leave. This is almost always a long-running PHP request, a stalled outbound API call, or a large download in progress. There is no timeout on a graceful restart — the parent waits indefinitely for those children. Find the culprit before you escalate to force:

httpd -S 2>&1 | head -20
apachectl fullstatus 2>/dev/null | head -30

If it truly must end, apachectl graceful-stop sends SIGWINCH, which drains children under the GracefulShutdownTimeout directive; its default value of 0 means wait forever, so set a real number of seconds before relying on it. When the timeout expires, remaining children are sent TERM.

The change did not take effect and nothing looked wrong. The syntax check failed and the restart was refused, but the error scrolled past or was swallowed by a script. Always run configtest as its own step, and in automation chain it with && so a failure stops the pipeline instead of quietly leaving the old config serving.

could not bind to address after a hard restart. The old parent had not fully released the port when the new one tried to claim it:

(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
no listening sockets available, shutting down

Find what still holds the socket with ss -ltnp | grep ':80 ', confirm no orphaned httpd remains with pgrep -a httpd, and start again. This failure mode is the practical argument for preferring a graceful.

cPanel restarts httpd underneath you. The chkservd service monitor checks enabled services and will restart Apache if it looks down — including during the seconds you deliberately had it stopped. If you need Apache down for maintenance, disable monitoring for it first in WHM’s Service Manager, and read the log to confirm what actually happened:

grep -i httpd /var/log/chkservd.log | tail -5

502s right after a deploy. Apache was reloaded while PHP-FPM was still restarting, so requests were proxied to a socket with nothing behind it. Reverse the order: FPM first, Apache second. The errors will name the socket in the Apache log — see reading the Apache error log on cPanel for how to read them.

When this is the wrong approach

A graceful protects the requests already in flight on one host. It does not make that host redundant. If your requirement is that a Listen change, an MPM swap or a kernel reboot is invisible to visitors, no amount of signal choice on a single Apache instance will get you there — the parent has to exit, and while it is gone the port is not answering. The real answer is a second host behind a load balancer that drains connections from one backend before you touch it, then the other. Similarly, if you find yourself reaching for a full restart weekly, treat that as a symptom rather than a routine: a module leaking memory, config drift forcing a re-init, or a deploy pipeline that is not actually reloading what it thinks it is.

Apache’s own stopping and restarting page is the authority on signal semantics, and the cPanel product documentation covers the service scripts and the Service Manager.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.