If you are running a blog or content management system like WordPress or Drupal on an Amazon micro or small instance you will likely have to make some optimizations to the Apache configuration. Otherwise the Apache webserver or the MySQL database will crash sooner or later and the dmesg command will show something like

[9681301.397227] Out of memory: Kill process 23954 (apache2) score 26 or sacrifice child [9681301.397260] Killed process 23954 (apache2) total-vm:361812kB, anon-rss:32540kB, file-rss:4kB [9749304.960885] type=1400 audit(1358511480.422:43): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=30604 comm="apparmor_parser"

You can test if your site needs optimization by running the simple ab Apache benchmarking tool that comes bundled with the Apache installation.

ab -n 5000 -c 20 http://www.yourserver.com/

This command may slow down your server a bit but may never crash it. If it does, edit the /etc/apache2/apache2.conf configuration file and make the following changes.

KeepAliveTimeout 3

StartServers 1 MinSpareServers 1 MaxSpareServers 5 ServerLimit 50 MaxClients 50 MaxRequestsPerChild 5000

Now restart Apache

/etc/init.d/apache2 restart

and run the ab command again to see if this fixes the issue. If it does not, check http://library.linode.com/troubleshooting/memory-networking#sph_mysql-low-memory-settings and reduce the MySQL memory usage, disable MySQL InnoDB support if you don’t use it, check the memory_limit in your php.ini and further reduce the Apache settings.