Optimizing Apache 2 Configuration for Smaller VPS Instances

I recently down-scaled the server which hosts this blog (one among a few). Being a Ubuntu server, it was trivial to install the LAMP stack, including Apache 2. However, I quickly discovered a problem with the default configuration on a server with a lesser amount of memory (in this case 512MB). The server would work just fine for a short while and then grind to a near halt, where even a SSH session becomes unusable. When I eventually got into the server, I listed the processes and found the ‘apache2’ process running several dozen times!

The default configuration for the Pre-fork MBM (Multi-Processing Module) reads as follows:

# prefork MPM

   StartServers          16
   MinSpareServers       16
   MaxSpareServers       32
   ServerLimit           400
   MaxClients            400
   MaxRequestsPerChild   10000

To something more reasonable to a server with limited memory, such as:

# prefork MPM

   StartServers         4
   MinSpareServers      4
   MaxSpareServers      8
   MaxClients           35
   MaxRequestsPerChild  10000

I found this has made my server much more stable – and I’ve not noticed any performance decrease from the new configuration.

Getting SSI to work in MAMP

It’s no secret that I adore my Mac, mostly because it just makes my life easier.  I enjoy the security of OSX, I love it’s responsiveness and I love that my operating system doesn’t punish me for installing applications and development stacks just to ‘play with them’.  A while ago, while looking for a stack that would let me quickly and effortlessly get Apache, MySQL and PHP5 working together without having to muss about with configs and the such, I discovered MAMP and frankly, I adored it instantly.  After a rather large download, it was effortless to install and running it was a cinch.  And better still, the server applications only run when you open the MAMP application and tell them to run, so that you dont loose vital system resources running services you dont need.

Additionally, my IDE of choice, NetBeans can integrate directly with MAMP, so that when you create (for sake of argument) a new PHP project and run it, it automatically puts the project files into the MAMP Apache directory (to be honest you do need to configure the path when you create the project, but its no big deal) making development painless and convenient.

But I did hit a snag recently when for a university assignment I was required to do a XHTML website using HTML Server Side Includes.  I was shocked when I ran my website and my SSI didnt work.

But there is a solution.

To make .shtml work, I deleted the comment-symbols ( # ) in the file http.conf (find it in /Applications/MAMP/conf/apache/ and at the time of writing was near lines 982:

# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml