AWS micro EC2 instance WordPress LAMP stack optimized low memory settings

Amazon Web Services EC2 micro instances are a good way to test and develop a LAMP stack running WordPress, but, the settings for Apache, MySQL and PHP on a Linux AMI (Amazon Managed Image), by default, tend to have memory settings too high for using on a micro EC2 instance. Which can cause the WordPress site to crash on a memory error.

SSHing into the EC2 instance and running the following commands will show what’s going on if your WordPress set-up does crash:
$ free -m This will display memory information. Check the ‘free’ column to see how much memory is actually free.
$ ps -aux --sort -rss This command will show the processes, sorted by memory usage.

If your Wordpres site has crashed because of a memory error it will be made evident by those commands output.

To tweak your memory settings to help prevent site crashes by memory, try the following in SSH.
$ sudo su become root
$ service mysqld stop stop MySQL
$ service httpd stop stop Apache
$ vim /etc/php.ini Use VIM editor to change PHP settings
Once you’ve opened the php.ini file in VIM (VIM cheatsheet), edit memory_limit = 100M
Exit and save the php.ini file.
$ vim /etc/httpd/conf/httpd.conf edit apache’s config file in VIM
Inside httpd.conf, edit the following values in the prefork.c module tag:
<IfModule prefork.c>
StartServers 3
MinSpareServers 2
MaxSpareServers 5
ServerLimit 10
MaxClients 10
MaxRequestsPerChild 1000

Exit and save the httpd.conf file.
$ vim /etc/my.cnf edit the mysql configuration file
Add the line under the [mysqld] list: innodb_buffer_pool_size = 1M
Exit and save.
$ service mysqld start start MySQL
$ service httpd start start Apache

Your WordPress site should now be up and running again.
Remember that these are setting to help your WordPress LAMP stack run on a micro instance, and probably should be changed back when taken live. Espcially if you want to support a lot of traffic!

Leave a comment if you have any tweaks or updates that you think can help improve memory usage of WordPress on a micro EC2 instance!