If you made the decision to move your WordPress install from shared hosting to a shiny new VPS you should consider optimizing Apache by making some tweaks to your httpd.conf file. Apache is a fast, reliable, and flexible server but is heavy on resources by default. If you are running a small VPS, and using it just for WordPress, you can make some small tweaks to your configuration and get some significant performance gains.
If you’re looking for some tips on SSL performance with your WordPress site be sure to check out our guide on using SPDY and SSL. If you need a WordPress theme, be sure to check out our WordPress templates or read about how to find the best WordPress themes.
Trim Down Those Modules
Open up the
httpd.conf file on your server in your favorite text editor and look for a bunch of lines starting with
LoadModule. It should look something like this:
# Example: # LoadModule foo_module modules/mod_foo.so # LoadModule auth_basic_module modules/mod_auth_basic.so LoadModule auth_digest_module modules/mod_auth_digest.so LoadModule authn_file_module modules/mod_authn_file.so LoadModule authn_alias_module modules/mod_authn_alias.so
The actual list will be much longer but you get the idea. You can disable these modules by “commenting them out”. Which essentially amounts to adding a
# in front of the line like so:
# LoadModule auth_basic_module modules/mod_auth_basic.so
You are going to disable a bunch of these modules that a basic WordPress website does not require. In fact, I want you to comment out every module EXCEPT FOR the following:
LoadModule authz_host_module modules/mod_authz_host.so LoadModule log_config_module modules/mod_log_config.so LoadModule expires_module modules/mod_expires.so LoadModule deflate_module modules/mod_deflate.so LoadModule headers_module modules/mod_headers.so LoadModule setenvif_module modules/mod_setenvif.so LoadModule mime_module modules/mod_mime.so LoadModule autoindex_module modules/mod_autoindex.so LoadModule dir_module modules/mod_dir.so LoadModule alias_module modules/mod_alias.so LoadModule rewrite_module modules/mod_rewrite.so
One of the lines you probably commented out was this one:
LoadModule negotiation_module modules/mod_negotiation.so
This provides some functions for auto-completing mistyped URL’s that you don’t really need. It also is required if you are serving multilingual pages. If that is the case then DO NOT comment out the above module.
If you did in fact comment out the
mod_negotiation.so module you will need to make a couple more tweaks. Find these two lines (they are in different locations) and comment them out:
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
ForceLanguagePriority Prefer Fallback
You should see a significant performance boost after disabling those modules. They were eating up a good size chunk of your limited system resources.
Apache MPM Prefork Module
Another handy tweak is to make some adjustments to the Apache MPM prefork module. This is assuming you are using Apache in prefork mode, which is highly recommended and likely if you are on a small VPS.
This module controls the number of processes and spare processes Apache will start and run. This is especially important if you are running a small VPS that is handling MySQL and Apache. Unless you are getting slammed with really heavy traffic on a regular basis (in which case you should be on a dedicated server) there is no need to be running the default configuration. Find these lines in your
<IfModule prefork.c> StartServers 8 MinSpareServers 5 MaxSpareServers 20 ServerLimit 256 MaxClients 256 MaxRequestsPerChild 4000 </IfModule>
ServerLimit controls the maximum configured value for MaxClients. Reducing MaxClients on a webserver that is serving dynamic content (e.g. WordPress) can make a big difference. If you experience a traffic spike on your VPS and your MaxClients is set too high your server will more than likely get stuck in an endless loop of swapping pages from physical memory to virtual memory, commonly referred to as thrashing. The accepted way of calculating an appropriate MaxClients value is dividing your total available system memory by the size per Apache process. For example, if you had a 500MB left for Apache to use and each Apache process was using around 10MB you would set your MaxClients to (512-12) / 10 = 50. To check real time memory usage on your VPS use top.
MaxRequestsPerChild limits the number of requests a child server will handle during it’s life. We can safely reduce this value and realize a small gain.
So let’s go ahead and pare down those values:
<IfModule prefork.c> StartServers 3 MinSpareServers 3 MaxSpareServers 10 ServerLimit 50 MaxClients 50 MaxRequestsPerChild 2000 </IfModule>
Remember these are not concrete “best” values, they depend on the size of your VPS and how small or large you Apache process is.
Optimize Your KeepAlive
KeepAlive. Find this line in your
and change it to:
KeepAlive turned on and make some additional tweaks.
If you decide to leave
KeepAlive turned on it is important you change the default KeepAliveTimeout value. This prevents unused connections from staying open for excessive amounts of time. Find this line in your
You want to leave this connection open for 2 seconds, just long enough for the client to request most if not all of the necessary files. So change that line to:
If you are going to leave
KeepAlive on you will want to increase MaxKeepAliveRequests. Setting this higher allows more requests per connection and increases efficiency. Find this line:
and change it to:
Another minor tweak that will give you a small performance boost as well as help reduce the effects of a DOS attack is changing the TimeOut Directive. This directive tells Apache how many seconds to wait while receiving an incoming request, processing it, and sending back a response. Find this line:
and change it to:
Restart Apache and Enjoy!
Now restart Apache and enjoy your performance boost! Always remember to backup your
httpd.conf file in case something goes wrong. Keep in mind this is just a sample configuration and we aren’t responsible if it breaks something on your server.
- Tuning Lamp Systems, Part 2: Optimizing Apache and PHP
- Apache Performance Notes
- Apache Performance Tuning
- Choosing MaxClients
- Tuning the Apache MaxClients parameter
Enjoy this post? Read more like it in Tutorials.