Server Optimization II – Apache

As already stated I do not want to reinvent the wheel at this point. There are many excellent tutorials like e.g. this one concerning the optimization of Apache. For this reason I only want to give a few short hints how I did the optimization in Gentoo. I only did a few and not all of the possible steps so be sure to read the mentioned tutorial (or others) carefully to identify the correct steps for you. In this post I will only mention software optimization which only brings small performance enhancements. If your server is seriously struggling under tons of requests, consider upgrading your hardware, too.

I did the following software related optimizations on Gentoo.

Cleaning the apache module list

Identifying the minimal module list for your configuration can be quite time consuming because often (at least in my case) you do not exactly know, which module provides which feature.
You can find a list of all modules and a link to their documentation in the Gentoo wiki. Personally I use php, url rewriting, logging, cgi, basic authentication, vhosts and subversion (and several other smaller features) and found the following list to be working for me. Insert your list into /etc/make.conf as the APACHE2_MODULES variable.

This is my configuration:

[code]APACHE2_MODULES=”actions alias asis auth_basic authn_alias authn_anon authn_default authn_file authz_default authz_user authz_host autoindex cgi dav deflate dir env expires filter headers log_config logio mime negotiation rewrite setenvif status unique_id vhost_alias dav_fs dav_lock dumpio ext_filter imagemap mime_magic”[/code]

For testing out needed modules, you do not need to recompile apache every time. Within a dynamic module configuration it is enough to edit the /etc/apache/httpd.conf, comment out the questionable modules, restart apache and determine if your applications still work as expected. But when you know which modules are needed, change the mentioned variable so that you do not have to compile unnecessary modules when you update apache.

After changing this variable you have to recompile and restart apache. Before you restart you should (if needed) update your config files because new modules may add new LoadModule definitions to httpd.conf. Be also sure to check for <IfDefine …> directives which only activate modules, if you added the value after IfDefine as an -D argument to /etc/conf.d/apache2.

Choosing the right MPM (Multi Processing Module)

When choosing the MPM I took the advice of the tutorial mentioned before and use the prefork module because our server only has two cores. If you want to save some compile time you can tell portage to only compile this MPM by setting APACHE2_MPMS=”prefork” in the make.conf. Like all other apache modules in Gentoo the worker can be configured in /etc/apache2/modules.d/ in 00_mpm.conf. In this file you can change essential parameters like the processes or threads apache should create on startup. You can see which MPMS are available and which parameters they use here.

Deactivating overrides and symbolic links

Deactivating overrides means deactivating .htaccess files in every directory which will be nearly impossible for hosting providers. But if you are the only one who updates the configuration or can manage to be the only one who does these updates, you can save significant processing time. The same applies to symbolic links. If you want to know how to do deactivate these features, look at the tutorial mentioned in the beginning (also for the deactivation of HostnameLookups).

Further optimizations

If you want to optimize apache further consider using a cache. Apache itself has several options described in the Caching Guide. Apart from that you can use a caching reverse proxy as for example Varnish to cache and redirect your requests between different servers.

I hope this article and the further documentation gave a rough overview of tuning apache for sites with numerous requests and helps you saving hardware.

Comments and corrections are, as always, welcome
Happy tuning

Regards,
Phillip

Leave a Reply

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

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.