Recomended Apache configuration?

Posted on

Recomended Apache configuration? – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, apache-2.2, performance, httpd, configuration.

Sorry to ask a question like this if its too superficial for you. Considering the information below, how would you configure httpd.conf?

The load time of pages reaches to 30 seconds when the server busy.


Quad-Xeon 3220 / 8GB memory / 2x250GB SATAII / 10TB BW / 1GiGE / 8 IPS (SoftLayer),
CentOS 5 (64-bit) Plesk 9.5

Linux 2.6.18-274.17.1.el5 #1 SMP Tue Jan 10 17:25:58 EST 2012 x86_64 x86_64 x86_64 GNU/Linux

Sites on the server receive around 500,000 pageviews and 200GB a day on average. There are around 1500 visitors online when the server busy according to

top - 11:15:08 up 23 days, 12:21,  1 user,  load average: 0.30, 1.09, 1.84
Tasks: 453 total,   1 running, 452 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.9%us,  2.8%sy,  0.0%ni, 90.3%id,  3.7%wa,  0.0%hi,  0.3%si,  0.0%st
Mem:   8165772k total,  8065268k used,   100504k free,   348884k buffers
Swap:  1052248k total,      208k used,  1052040k free,  6466136k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                              
15573 mysql     15   0  601m  80m 4520 S 35.1  1.0   2026:37 mysqld                                                                                                               
19381 apache    15   0  307m  15m 3312 S  1.0  0.2   0:02.73 httpd                                                                                                                
13230 apache    15   0  307m  15m 3296 S  0.7  0.2   0:03.74 httpd                                                                                                                
14152 apache    15   0  307m  15m 3284 S  0.7  0.2   0:03.91 httpd                                                                                                                
16147 apache    15   0  307m  15m 3296 S  0.7  0.2   0:03.14 httpd                                                                                                                
16957 apache    15   0  307m  15m 3292 S  0.7  0.2   0:03.03 httpd               

httpd.conf file:

Timeout 60
KeepAlive On
MaxKeepAliveRequests 300
KeepAliveTimeout 5
<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
<IfModule worker.c>
StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75 
ThreadsPerChild     25
MaxRequestsPerChild  0

Solution :

Things to consider:

  1. Your maximum number of online clients is ~1500
  2. The amount of memory each httpd process uses (about 300MB from your output) and the amount of memory your machine has.

It would be a good idea to thoroughly examine your httpd.conf and remove any unnecessary modules to cut down your memory footprint. Once you’ve done that, you can start to raise MaxClients and ServerLimit gradually.

You’ll want to raise StartServers, MinSpareServers and MaxSpareServers too, but again do this gradually and monitor memory usage and site performance for a while after each change.

Other things to consider would be to place something like Varnish in front of Apache or (as Fernando suggests) APC.

If possible, try to switch to another webserver like Nginx or Lighttpd. Apache is great but usually it doesn’t handle busy websites well.

If you can’t, no problem. Here are some tips that can help you:

1. Disable logs

If your application doesn’t depend on log files and you use Analytics or other service for stats you can disable logs. You will see I/O dropping because apache doesn’t have to write every request on disk.

2. Are you using PHP? Opcode cache is mandatory!

I prefer APC because it’s simple to install, stable and is going to be part of PHP soon. To install it simply run:

pecl install apc

Them add the following line to your php.ini:


Restart your webserver and watch load going down.

3. Change to another MPM

Changing to worker or event MPM can help in some causes. It really depends on the type of files that you’re serving. I saw cases where the load dropped after this and others were running as prefork or worker didn’t made any considerable difference.

Note: you can break PHP if you change for worker and you’re running it as a DSO module. Check this first.

Leave a Reply

Your email address will not be published. Required fields are marked *