Amazon AWS Micro Instance runs out of memory with Apache/MySQL/Wordpress

Posted on Wednesday, January 9, 2013



Recently I set up a micro instance within the Amazon cloud to act as a Wordpress server, running Ubuntu 12.04 Server. 

A micro instance only has 613MiB of memory, which is not much in the day and age but good enough for a lightly used wordpress site.

However after setting my site up and letting it run for a few days the MySQL database, running on the same machine, shut down.   I restarted it and chalked it up as a one-time fluke.  But it did it again the next night.   I checked the server and it was not working because MySQL was down.   Everything else was just fine.   So I restarted MySQL and started investigating.




I eventually discovered that I was running out of memory and MySQL was being shut off.   I discovered this in my logs.  I ran the following command.



      > cat /var/log/syslog.1 | grep mysql


And discovered that MySQL was shutting down every night due to out of memory errors.

To fix this I did the following

Update the php.ini memory limit


      >  sudo vi /etc/php5/apache2/php.ini


Update
memory_limit = 80M










Edit apache2.


      >  sudo vi +99 /etc/apache2/apache2.conf


Update to










      >  sudo vi +116 /etc/apache2/apache2.conf













      >  sudo vi +134 /etc/apache/apache2.conf












Reboot the server to pick up all the changes


      >  sudo reboot now




Since these updates I have not had any memory issues.

2 comments:

  1. This is brilliant! I've had exactly the same issues, this has saved my day. Thanks

    ReplyDelete
  2. I was stumped when this first happened. A coworker actually suggested it might be a memory issue, so the thanks should be his for setting me down on the path that led me to this solution.

    ReplyDelete