Our team is often asked to tune apache to run more smoothly, more quickly, and more reliably. With a few simple server side tweaks you can easily polish your server till it is ready for 'production' use of your website. The following is based on the default configuration of most apache installs.
Reducing memory use
Some features in apache can be memory hogs, more memory per process means less workers can run in the available memory on your server. If apache is not configured correctly, under load this can also affect server stability. There are a few of ways you can improve this...
- disable unused apache modules
- Limit the number of apache processes that can be started, via the MaxClients setting. This keeps apache from overloading the underlying server.
- Reduce the minimum number of processes apache starts, lets apache return memory to the server when it is not using it.
Many well known content management systems use php (eg WordPress, Drupal, and Silverstripe), the apache server has to load that in as well, before content can be served.
- disable unused php modules
- limit the amount of memory php uses (eg in php.ini edit memory_limit=xxxM)
- keep your php code compact (ie avoid loading unused code, plugins etc)
Eliminate unwanted http headers
By default apache advertises a lot of information in every request. Individually it may not seem like much, but by reducing the amount of data in each request, overall connection time is reduced, which means apache can respond faster to the next thing.
- set ServerTokens to Off or Prod
- set ServerSignature to Off
This can also makes a small but significant difference to data usage on a busy web server.
Improve apache connection speed
The default settings for apache in most distributions are reasonable, but tend to favour developers, where testing needs to be easy, rather than for production use.
- reduce persistent connections (ie MaxKeepAliveRequests)
- limit how long connections can wait (ie Timeout and KeepAliveTimeout)
- disable hostname resolution (ie HostnameLookups Off)
Faster page generation
Keep your web content small and compact, this will mean less work for the web server to send to a visitor. Make some effort to cache content locally as well. Some easy and well known methods for doing that include the PHP APC module (now replaced with Optimizer+) and memcached.
Reduce server logging
Logging data from your web server can be immensely useful in figuring out issues after you go into production. However you really don't want debug data needed by your developers filling up disk space and creating unwanted disk writes.
So... turn off logging that you don't need, and just keep the essentials in place. You can always enable more verbose logs when troubleshooting if that is needed (and you can't do that on your development server).
Avoid using .htaccess files
This is a tricky one, since many well known webapps use .htaccess files to help secure and manage the behavior on various parts of a site. Make up your own mind about this, but do read the recommendations by the apache developers (for apache 2.4 go here)
By using a lot of the tweaks described above (and others), server security is often improved as well, a nice side effect.
Tuning apache for more performance is a pretty easy thing to do on the surface, there is still a lot you can do to get the last erg out of your web server, but these tips are a good place to start, and should work for most setups. Often these tweaks will be useful even if you have a hosting control panel in place.
More refined tuning often depends on exactly your website setup. If you need a hand with this kind of work, pop in a support ticket with details on what you want to see, and we can help you get your site racing.