cPanel Config

Welcome to cPanelConfig the fastest growing cPanel configuration and troubleshooting guide on the internet. Please take the time and register. We would love to have your contribution to this completely free cPanel resource. We are updating this daily so be sure to visit us on a regular basis.

Apache tuning and optimization cPanel 11.x

1 Star2 Stars3 Stars4 Stars5 Stars (10 votes, average: 4.30 out of 5)
Loading ... Loading ...

Posted by yolau

In this article I will try to teach you all the tricks to make your webserver (apache) run faster. While the information in this article is not necessary new I tried compressing all the useful tips in one short article.
I’ve put this article on hold for far too long but here it it.

I would like to start by saying that this article is not necessary meant for cPanel powered servers but I will make all my references to this type of servers. You can still apply all the tips here to all apache based webservers so don’t stop reading here if you don’t have cPanel !

OK, lets start.
First login to your server as root using ssh.

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

  • MaxClients - Total number of concurrent connections.
    Locate it in the configuration file. This should be set to a reasonable value. I suggest using this formula to determine the right value for your server.
  • MaxClients = 150 x RAM (GB)

    So for example if you have 2 GB or 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 them 2 GB of RAM and you run a resource intensive website consider increasing MaxSpareServers.

  • MaxRequestsPerChild – Controls the number of request the a 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. I suggest setting it to:
  • MaxRequestsPerChild 1000

  • KeepAlive and MaxKeepAliveRequests – 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 a more powerful hardware. If you decide to KeepAlive I suggest you set MaxKeepAliveRequest low to something like 2 seconds.
  • StartServers – 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 ok. 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

/usr/local/cpanel/bin/build_apache_conf

Hope this article will help a lot a people. I would like to hear your feedback on this, so please leave a comment !

Share this:
  • Digg
  • del.icio.us
  • Slashdot
  • StumbleUpon
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • De.lirio.us
  • Furl
  • MyShare
  • Smarking
  • Technorati
  • YahooMyWeb

If you enjoyed this post, make sure you subscribe to my RSS feed!

11 Responses to “Apache tuning and optimization cPanel 11.x”

  1. [...] if you like to tinker, there are some good guides about optimizing your new Apache server through this link and this other [...]

  2. Thank you for the write-up. I utilized your suggestions on my web server and I hope they will help speed things up a bit, especially since my web server is only a laptop.

    I have one input/suggestion though. In your write-up, you talk about setting StartServers to a value like 5, but there are two “StartServer” locations in the httpd.conf file. Which one is the proper one to change? One is set to 10 by default, the other is set to 2. Would it be a good idea to clarify which one a user should change?

    Thanks again!

  3. I like what I see here

  4. Thanks for sharing

  5. I’m assuming this post is for apache 1.X and not 2.2.X as these directives don’t exist in 2.2.8, I would love to see a tutorial on the latest apache.

  6. [...] if you like to tinker, there are some good guides about optimizing your new Apache server through this link and this other [...]

  7. hi
    i used ur said optimization for my website (http://www.theatremp3.net) with 5000+ unique hits a day and it turned out to be a nice one ;) :D
    Thanks bro for such an informative and helpful article.

  8. Thank you for sharing.

  9. It may be strange, but I don’t see any of the commands in my httpd.conf file. Why is this so?

    I have added the same.

  10. hello guyz m not getting any such thing in httpd.conf

    i have open through winscp can any one help me ?

    i search for text maxclients but m not getting it. please help me out

  11. In latest cpanel/whm built the following httpd configuration for performing optimization should be done via:

    /usr/local/apache/conf/httpd-std.conf

    Try to access this file and you should see the settings that needed to tune up for server performance.

Leave a Reply