Today we will talk about Linux and apache tips and tricks that will help webmaster to tune their dedicated server to handle high traffic.
httpd.conf is a file file, usually located at /usr/local/apache/conf/httpd.conf path containing configuration settings for apache server. Cannot find the location of the file? Use locate command: >cd / then >locate httpd.conf. You may find the values in conf/extra directory. Search for http-mpm.conf and http-default.conf
Main parameters to tune are:
In Apache MPM Prefork Module:
Apache MPM Prefork Module
Another handy tweak is to make some adjustments to the Apache MPM prefork module. This is assuming you are using Apache in prefork mode, which is highly recommended and likely if you are on a small VPS.
This module controls the number of processes and spare processes Apache will start and run. This is especially important if you are running a small VPS that is handling MySQL and Apache. Unless you are getting slammed with really heavy traffic on a regular basis (in which case you should be on a dedicated server) there is no need to be running the default configuration. Find these lines in your httpd.conf file:
MinSpareservers and MaxSpareServers control the number of spare processes your webserver is permitted to run and StartServers controls how many are started by default.
ServerLimit - controls the maximum configured value for MaxClients.
MaxClients – sets the limit on the number of simultaneous requests that can be supported.
Reducing MaxClients on a webserver that is serving dynamic content (e.g. WordPress) can make a big difference. If you experience a traffic spike on your VPS and your MaxClients is set too high your server will more than likely get stuck in an endless loop of swapping pages from physical memory to virtual memory, commonly referred to as thrashing. The accepted way of calculating an appropriate MaxClients value is dividing your total available system memory by the size per Apache process. For example, if you had a 500MB left for Apache to use and each Apache process was using around 20MB you would set your MaxClients to (512-12) / 10 = 50. To check real time memory usage on your VPS use top.Want to set it to a larger value? Add more physical RAM. In other words, calculate the average of your httpd process, divide total available memory by the average leaving some for the system. E.g. in case of 1 Gig RAM and average httpd process size 7MB on this server it is safe to set it to 100.
If you use MySQL database, MaxClients parameter should be equal or close to max_connections parameter in MySQL conf file (my.cnf)
MaxRequestsPerChild - limits the number of requests a child server will handle during it’s life. We can safely reduce this value and realize a small gain.
So let’s go ahead and pare down those values:
Remember these are not concrete “best” values, they depend on the size of your VPS and how small or large you Apache process is.
Optimize Your KeepAlive
and change it to:
If you decide to leave KeepAlive turned on it is important you change the default KeepAliveTimeout value. This prevents unused connections from staying open for excessive amounts of time. Find this line in your httpd.conf file:
You want to leave this connection open for 2 seconds, just long enough for the client to request most if not all of the necessary files. It is best to se it to minimum, 1-3 seconds. So change that line to:
If you are going to leave KeepAlive on you will want to increase MaxKeepAliveRequests. Setting this higher allows more requests per connection and increases efficiency. Find this line:
and change it to:
MaxRequestsPerChild – sets how many requests to serve per new httpd child process. You may set it very low, thus constantly freeing the memory, however on a particular case values like 15 or 20 may work well. As an example our site showing 10 images per page has this parameter set to 15.
Another minor tweak that will give you a small performance boost as well as help reduce the effects of a DOS attack is changing the TimeOut Directive. This directive tells Apache how many seconds to wait while receiving an incoming request, processing it, and sending back a response. Find this line:
and change it to:
After you change settings in httpd.conf do not forget to restart apache. You may do this from control panel or from command line > service httpd restart
Also modules are important. For example mod_expires.c. How to check if modules are enabled:
We use Hosting and VPS Hosting, from: www.star-host.org
We like and trust them.
Good prices, high security.