MinhTech.com

Yet another technology tutorial blog.

CentOS Install & Configure Apache

By • Dec 27th, 2008 • Category: Featured Linux, Linux

Here is how to install and tune the Apache HTTP server on CentOS 5.2.

First, install Apache via yum:

> yum install httpd

Next, we will modify the configuration file. Edit the timeout parameter:

> vi /etc/httpd/conf/httpd.conf
Timeout 60

We will be limiting the number of processes to conserve memory so we do not want them held up for too long.

Edit the keep alive parameters:

KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 2

We want to allow a browser to keep alive its connection with the server and use the same connection to request multiple files and maximize bandwidth. Fewer connections means less overhead. We have instructed Apache to close connections after 2 seconds of inactivity. The default 15 seconds is too long. We want to give the browser plenty of time to submit requests but close the connection as soon as possible.

Edit the prefork multi-processing module (MPM):

<IfModule prefork.c>
   StartServers 4
   MinSpareServers 4
   MaxSpareServers 6
   ServerLimit 16
   MaxClients 16
   MaxRequestsPerChild 4000
</IfModule>

So we are instructing Apache to start 4 server processes and keep up at least 4 spare processes ready to go at all times. It may scale up to 16 active processes with a maximum of 6 spare processes at any given moment. Tune these numbers by considering physical memory available to Apache. “ps -ylC httpd –sort:rss” shows the physical memory usage for each process. Spawning too many processes will cause swap and slow the machine down to a crawl.

We are also instructing Apache to recycle processes by having each one handle 4,000 requests before it is killed. Spawning a new process requires a lot of overhead. On the other hand, we do not want to keep a process alive forever since each request may allocate more and more memory that will not be released (i.e. memory leak).

Turn off hostname resolution:

HostnameLookups Off

Enable compression:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent env=!dont-vary

We are instructing Apache to compress files of several MIME types to speed up transmission and conserve bandwidth. Some older browsers partially support or do not support gzip compression so we limit or disable compression when they interface the server.

Finally, start Apache:

> /etc/init.d/httpd start
Starting httpd: [ OK ]
> chkconfig –level 2345 httpd on

is a technology junkie.
Email this author | All posts by

One Response »

  1. Hello may I quote some of the information here in this entry if I link back to you?

Leave a Reply