Apache For Small VPS
Posted in Techno Stuffs on November 29th, 2007
Oftentimes, the default configuration of your servers would not fit your needs. Trust me on this. ![]()
One good example would be the Apache configuration. When I tried installing Apache on my VPS, I just installed it manually, hardened the security, configured my websites and that’s it. I then became busy for a few weeks, and never got the chance to check on my VPS and if everything was optimized. Besides, all my websites seems to be working well so I never really thought there’s an urgent need to optimize things. It was only when I added a community website that’s taking quite a number of hits a day that I took the time to look into how my VPS resources were being used. I’m glad I did ‘coz I was surprised to see that I am running out of memory, and come to think of it it shouldn’t happen at all considering that the hits are not that much to bring down even a small-scale VPS with around 256MB of RAM.
So I double-checked my configuration and saw that there’s quite a lot of HTTP process being spawned. This seems to be an overkill with my current traffic. By default, Apache’s configuration for the Prefork MPM module would be:
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
This was too much and I don’t think it’s worth creating a lot of spare server proceses which I don’t actually use. Moreover, I had to setup the server limits to fit my current VPS resources. So what I modified the configuration this way.
<IfModule prefork.c>
StartServers 1
MinSpareServers 1
MaxSpareServers 5
ServerLimit 5
MaxClients 5
MaxRequestsPerChild 4000
</IfModule>
After these settings, I saw a lot of improvements on my server. Even on the busiest time of the day, my VPS would only be using around 50%-60% of its RAM, and still my websites’ response time was still quick. This won’t be the ideal setup for everyone, since there’s a lot of things you need to consider such as website traffic, the services you run in parallel with Apache, and some other internal server workings that differs from one user to another. There’s also a lot of Apache optimization that I had not mentioned here ( but I’ll find time to blog about it soon), but as a rule of thumb on most server configuration, “Don’t create what you can’t use, and don’t use what you can’t create”. ![]()
