Some Simple Tweaks to Optimize Apache in cPanel


The default Apache settings on cPanel are something that can be improved on. Here are some simple tweaks to optimize cPanel server.

All the important configuration options are stored by Apache in a config file called httpd.conf that is located at /usr/local/apache/conf/httpd.conf. We will start by opening this file in your favorite text editor.

For exemple:

nano /usr/local/apache/conf/httpd.conf


A total number of concurrent connections. Locate it in the configuration file. This should be set to a reasonable value. We suggest using this formula to determine the right value for your server.

MaxClients = 150 x RAM (GB)

So for example, if you have 2GB of RAM set this value to 300. There is no reason for you to set it any higher unless you have a specific problem with this value. A high value can lead to a complete server hang in case of a DOS attack. A value too low can create timeout problems for your clients if the limit is reached.

MinSpareServers and MaxSpareServers:

MaxSpareServers and MinSpareServers control how many spare (unused) child-processes Apache will keep alive while waiting for more requests to put them to use. Each child-process consumes resources, so having MaxSpareServers set too high can cause resource problems. On the other hand, if the number of unused servers drops below MinSpareServers, Apache will fork (an expensive operation) new child-processes until MinSpareServers is satisfied.

Leave those values to:

MinSpareServers 5 MaxSpareServers 10

If you have more then 2GB of RAM and you run a resource intensive website consider increasing MaxSpareServers.

*MaxRequestsPerChild – Controls the number of requests the child serves before the child is killed. This should not be set too low as it will put an unnecessary load on the apache server to recreate the child. We suggest setting it to:

MaxRequestsPerChild 1000

KeepAlive and MaxKeepAlive Requests:

KeepAlive provides long-lived HTTP sessions which allow multiple requests to be sent over the same TCP connection. In some cases, this has been shown to result in an almost 50% speedup in latency times for HTML documents with many images, but having keepalive on is also a resource intensive setting.

Here comes the big question: To KeepAlive or not to KeepAlive? Well, the opinions are mixed here, some say to KeepAlive some say not to. If you want to hear my option I would say NOT to KeepAlive if you are running a shared hosting business or if you want to get the most out of your hardware. You should KeepAlive only if the loading time of your pages is the most important factor in your business and you have the money to invest in more powerful hardware. If you decide to KeepAlive we suggest you set MaxKeepAliveRequest low to something like 2 seconds.

Start Servers:

Sets the number of child server processes created on startup. This setting depends greatly on the type of webserver you run. If you run low traffic websites on that server set it low to something like 5. If you have resource intensive websites on that server you should set it close to MaxClients.

* Timeout – The amount of time Apache will wait for three things: the total amount of time it takes to receive a GET request. The amount of time between receipt of TCP packets on a POST or PUT request. The amount of time between ACKs on transmissions of TCP packets in responses. The default value is 300. You should set time to something a bit lower. A setting of 150 is probably okay. This will also help in case of small DOS attacks like to ones targeting some phpBB forums. Do NOT set it any lower then 90 as your users will start having timeout problems.

After you have done all the necessary changes you can go ahead and restart Apache.

service httpd restart

It should restart without any problems. If it doesn’t please double check the changes that you done.

Important Notice!

After upgrading to cPanel 11 and recompiling Apache. There is an extra step that you have to do so that the changes that you done to httpd.conf aren’t lost. Starting with cPanel 11.x all the Apache setting are also stored in a database and the configuration files are recreated each time an account is added or a recompile is done. To also save the changes in the database you will have to run:

/usr/local/cpanel/bin/apache_conf_distiller –update

You can check to see, if the changes were accepted and will not be discarded at the next Apache recompile by running.


If you feel this is tricky and you can’t take any risk, our Web Hosting experts can assist you in getting this fixed at a pocket-friendly price. All you need to do is to contact us and we’ll take care of the rest.

To get updates follow us on Facebook, Twitter, LinkedIn

Subscribe to get free blog content to your Inbox