Tune Apache settings in WHM Global Configuration
Adjust KeepAlive, Timeout, ServerLimit and MaxRequestWorkers in WHM, and add custom Apache directives with the Include Editor so they survive rebuilds.
- Advanced
- Linux VPS
- 4 min read
On a cPanel server you should never edit httpd.conf directly. cPanel rebuilds that file from templates, and your change disappears at the next account creation or update. Instead, WHM gives you Global Configuration for the common settings and the Include Editor for anything else. This guide covers both and how to test changes before they go live.
RunRacks does not sell cPanel licences. You buy one from cPanel or a partner and install it on your RunRacks Linux VPS.
Before you start
- Root access to WHM and SSH.
- Know your MPM. Run
/usr/sbin/httpd -V | grep -i mpm. Worker limits mean different things under prefork and event. - A copy of the current configuration:
cp -a /etc/apache2/conf/httpd.conf /root/httpd.conf.$(date +%F)Open Global Configuration
In WHM, go to Service Configuration » Apache Configuration and click Global Configuration. Each field maps to an Apache directive. When you click Save, WHM rebuilds httpd.conf, checks the syntax and restarts Apache. If the check fails, WHM keeps the old configuration.
Settings worth reviewing
KeepAlive
- Keep-Alive: lets a browser reuse one connection for several files. Leave it On.
- Keep-Alive Timeout: seconds Apache keeps an idle connection open. Under prefork, each idle connection holds a whole process, so keep this short, for example
2to5. Under event, idle connections are cheap and a slightly longer value is fine. - Max Keep-Alive Requests: requests allowed per connection. A value of
100or more is normal.
Timeout
Timeout is how long Apache waits on a slow client or backend. The Apache default is high. A value such as 60 to 120 stops stuck connections from piling up, but long uploads or slow reports may need more. Match it to your longest legitimate PHP request.
ServerLimit and Max Request Workers
- Max Request Workers: the maximum number of requests served at the same time. Requests above this wait in a queue.
- Server Limit: the maximum number of Apache processes.
Under prefork, MaxRequestWorkers equals the number of processes, so it is limited by RAM. Under event or worker, MaxRequestWorkers is ServerLimit multiplied by ThreadsPerChild. Size it against your PHP-FPM capacity, as explained in switch Apache MPM to event.
Setting MaxRequestWorkers far above what memory allows under prefork can make the server swap and stop responding under load. Raise it in small steps.
Other useful fields
- Server Tokens and Server Signature: set to the least revealing options so Apache does not advertise its version.
- Trace Enable: set to Off.
Add custom directives with the Include Editor
For directives without a field, open Service Configuration » Apache Configuration » Include Editor. There are three include points:
- Pre Main Include: at the top of
httpd.conf, before the main settings. Use it for global directives such asThreadsPerChildor extra modules settings. - Pre VirtualHost Include: after the main settings and before the virtual hosts. Use it for directives that every site should inherit.
- Post VirtualHost Include: at the end of the file.
Choose All Versions from the menu, add your lines and click Update. For example, to add a security header to every site:
<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
</IfModule>The include files are stored in /etc/apache2/conf.d/includes/, such as pre_virtualhost_global.conf. They survive rebuilds.
Per-domain custom directives
To change one site only, create a file in the userdata include folder for that domain, then rebuild:
mkdir -p /etc/apache2/conf.d/userdata/ssl/2_4/USER/example.com
nano /etc/apache2/conf.d/userdata/ssl/2_4/USER/example.com/custom.conf
/scripts/rebuildhttpdconf
/usr/sbin/httpd -t && /scripts/restartsrv_httpdUse the std folder instead of ssl for plain HTTP. Replace USER with the cPanel username.
Check it works
Test the syntax and confirm a directive is active:
/usr/sbin/httpd -t
grep -n "KeepAliveTimeout\|MaxRequestWorkers" /etc/apache2/conf/httpd.conf
curl -sI https://example.com | grep -i x-content-typeSyntax OK and your new values in the output show the change is live.
Troubleshooting
- Change lost after an update: you edited
httpd.confdirectly. Move the change into Global Configuration or an include file. - WHM refuses to save: the syntax check failed. Read the error, fix the include and save again.
- "server reached MaxRequestWorkers" in `/etc/apache2/logs/error_log`: raise it gradually and check that memory and PHP-FPM can keep up.
- Slow uploads cut off: Timeout is too short for large uploads. Raise it for the whole server or in a per-domain include.
Next steps
- Put a cache in front of Apache: enable NGINX reverse proxy on cPanel.
- Restart services cleanly after changes: restart services in WHM.
- Change modules and PHP builds: EasyApache 4 guide.
Was this guide helpful?
Still stuck?
Ask RunRacks AI for a quick answer, or open a ticket and our team will take a look at your server.
Related guides
Control panels
How to install Plesk on a Linux VPS (AlmaLinux and Ubuntu)
Install Plesk on a fresh Linux VPS with the official one-click installer, apply your licence key and log in to the panel for the first time on port 8443.
- Beginner
- Linux VPS
- 8 min read
Control panels
CyberPanel: back up and restore a website
Create on-demand and scheduled website backups in CyberPanel, download the archives off the server, and restore a site from a backup when something breaks.
- Intermediate
- Linux VPS
- 6 min read
Control panels
Plesk Backup Manager: schedule backups and restore a site
Set up scheduled backups in Plesk Backup Manager, keep a copy off the server, and restore a single domain or subscription when something goes wrong.
- Intermediate
- Linux VPS
- 7 min read