Part of the core design of cPanel is to install and fully manage the web service process. By default this process is Apache, as provided by EasyApache. For various reasons 1 a server admin may not want to use that installation of Apache, or even use a different web service. In such situations it is advantageous to disable cPanel’s management of the web service.
There are several ways to disable Apache restarts on a cPanel server. We’ll look only at the manual method. This involves touching one of the following files:
If any of those files exist Apache restarts handled by /scripts/restartsrv_httpd will not occur. That script will silently exit. However that script is not the only method cPanel has of restarting Apache. The other ways cPanel & WHM can restart Apache are:
- Executing /usr/local/cpanel/bin/safeapacherestart
- Calling the Cpanel::HttpUtils::ApRestart::safeaprestart 2 function
Before cPanel & WHM version 11.28 neither of the above methods will observe the flag files. This means you cannot effectively disable cPanel-managed restarts, at least with an unmodified product.
On my Debian-cPanel3 server the problem was exacerbated by the behavior of Cpanel::HttpUtils::ApRestart::safeaprestart. This function first looks for a process named httpd in the process table. Debian names the Apache process apache2. Since the function cannot found what it is looking for it switches to force mode. In force mode the function kills anything bound to port 80.
As noted above the good news is this is addressed in cPanel & WHM version 11.28 and newer. For older systems though you may accomplish this via a patch to Cpanel::HttpUtils::ApRestart::safeaprestart:
Note: patch removed as it is not needed on newer systems.
Next time we’ll examine modifying the Web service monitoring provided by chkservd
Some of these reasons include: running a different Web service, such as nginx; using the Apache install provided by the Operating System vendor; having a specialized monitoring and uptime guarantee service; etc. ↩
This function is called by various scripts, notably /scripts/checkerrorlogsafe which is called during upcp. It is also called from within the various cPanel binaries. ↩
Since writing this article cPanel & WHM changed a lot of its internals. Due to these changes I no longer recommend attempting to use Debian with cPanel & WHM. If you would like to see official support, I strongly recommend you add your voice to the feature request. ↩