Apache Performance Tuning

Posted on 15th Mar 2012

When working with Apache servers on a regular basis it's a good idea to have a few performance tweaks under your belt to get the best out of your sites from the get go.

This article will provide some basic apache (httpd) performance tuning. The objective of this article is to perform simple edits that will allow your (dv) server to run with less memory and to ensure higher availability under heavier loads.

Apache Timeout setting

The Timeout setting is the number of seconds before data "sends" or "receives" (to or from the client) time out. Having this set to a high number forces site visitors to "wait in line" which adds extra load to the server.

First, backup the file with the following command:

# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.bkup.kb-246.1

The following command opens httpd.conf and searches for the term Timeout:

vi +/Timeout /etc/httpd/conf/httpd.conf

You should see the following lines:

#Timeout: The number of seconds before receives and sends time out.
Timeout 120

Edit the section that reads:

Timeout 120

Change to a more reasonable value like the following:

Timeout 20

Save this file by pressing the escape key followed by :wq! which will save the file and exit vi.

Then restart Apache to apply the changes:

/etc/init.d/httpd restart

Editing the php.ini file

There are a few parameters that I tend to adjust in the php.ini file, normally to allow larger files to be uploaded through forms, to turn of PHPs safe mode or to allow more memory allowance for PHP executions. These parameters include:

safe_mode
register_globals upload_max_filesize post_max_size max_execution_time memory_limit

Use the following command at the command prompt to start editing:

vi /etc/php.ini

If you have upgraded to PHP5, the ini is located at

/opt/php51/etc/php5/fastcgi/php.ini

If you are looking for a specific parameter and would like to go straight there, type the following:

vi +/parameter /etc/php.ini

Example:

vi +/safe_mode /etc/php.ini

When you are finished editing your php.ini, you will need to restart your apache server. Run the following command:

/etc/init.d/httpd restart

More advanced optimisation techniques

You can find more official documentation on performance tuning for Apache over at their site. These optimisations are not for the faint hearted!