Putting a LAMP VPS on a diet

Having a VPS with 128M of ram and wanting to run LAMP on it successfully is no mean feat. I wanted a selection of php/mysql based applications to run on the server.

  • Wordpress(naturally)
  • Mediawiki
  • Ampache

At first I installed the vanilla apache2 and mysql packages and fired them up because I had no experience of anything else but by default my apache was using up nearly 30mb of ram and had 5 children, mysql was a similar affair except it used a threaded modal instead.. My memory usage quickly shot up to nearly full capacity pretty quickly. A quick Google later and I came across a guy who has optimized mysql for low memory situations, and I scrapped apache and went for the lighter lighttpd.

Heres the changes I made to my.cnf(mysql).

< key_buffer = 16M
< max_allowed_packet = 16M

> key_buffer = 4M
> max_allowed_packet = 2M
54c54
< thread_cache_size = 8

> thread_cache_size = 3
61,62c61,62
< query_cache_limit = 1M
< query_cache_size = 16M

> query_cache_limit = 2M
> query_cache_size = 128K
96c96
< #skip-innodb

> skip-innodb
120c120
< key_buffer = 16M

> key_buffer = 4M

This left mysql using 2.9% of memory, which for a database is not too bad at all.

I then installed lighttpd which required me to enable the universe and multi verse apt sources, this is because lighttpd is under the BSD license. Of course then I needed to install PHP support, this meant installing the php5-cli package and enabling the fastcgi lighttpd plug in using lighty-enable-mod. Then for some reason lighttpd kept crashing when i tried to start it, I looked in the configuration files and narrowed it down to /etc/lighttpd/conf-enabled/10-fastcgi.conf in which i changed the line “PHP_FCGI_CHILDREN” => “4″, to “PHP_FCGI_CHILDREN” => “0″ and that lighttpd started successfully and to my astonishment all my PHP applications worked out of the box, as before with apache, thats mediawiki, wordpress and ampache and with lighttpd sitting at 0.6% memory usage I was laughing. although php-cgi, which handles all the PHP pages was at 5.6% but thats understandable.

Of course strictly speaking this isn’t a LAMPS configuration now more like LLMPS, but it does the job better!

Leave a Reply


Copyright © 2012 All Rights Reserved.
No computers were harmed in the 0.162 seconds it took to produce this page.

dmarkey.com