Configure Apache and Mysql for hosting WordPress on Amazon EC2 Micro Instance

It may not be a good idea to host your WordPress blog on Amazon EC2 micro instance without properly configuring Apache and Mysql. Based on my experience in the past week, Apache had been eating 300M+ memory and Mysql kept shutting down once a day.

A piece of Mysql error messge at /var/log/mysql.log is:

130507 12:30:52 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(135987200 bytes) failed; errno 12
130507 12:30:52 InnoDB: Completed initialization of buffer pool
130507 12:30:52 InnoDB: Fatal error: cannot allocate memory for the buffer pool
130507 12:30:52 [ERROR] Plugin ‘InnoDB’ init function returned error.
130507 12:30:52 [ERROR] Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed.
130507 12:30:52 [ERROR] Unknown/unsupported storage engine: InnoDB
130507 12:30:52 [ERROR] Aborting
130507 12:30:52 [Note] /usr/libexec/mysqld: Shutdown compete

If your blog is just a personal one (not a news center with hundreds of thousands of PV), to avoid the issues I was having you may need to configure Apache and Mysql in this way:

Apache:

Edit /etc/httpd/conf/http.conf, search for section “Server-Pool Size Regulation” and change the default setting to:

StartServers 3
MinSpareServers 2
MaxSpareServers 5
MaxClients 10
MaxRequestsPerChild 1000

then run sudo service httpd restart, restarting Apache to apply the change.

Apache memory usage was reduced from 750M to around 200M.

image

Mysql

Simply copy the one of sample setting files to etc by

cp /usr/share/mysql/my-small.cnf /etc/my.cnf

my-small.cnf is optmized for small server as its name suggests. If this configuration cannot satisfy your need, perhaps what you really need is a EC2 small instance or even bigger.


Additionally I recommend some cool tools/services for optimizing/monitoring your blog:

  • Mod_pagespeed: a magic module powered by Google for apache http server that greatly improves the performance of your site.
  • Newrelic: Free but powerful service for application performance management & monitoring. Sign up an account and deploy it on your instance in 10 minutes as I did.
  • segment.io: A YC start-up company founded by a group of genius dropped from MIT, providing a packaged solution for monitoring and analyzing the traffic of your sites.
  • Leave a Reply

    Your email address will not be published.