Moving from Apache to Nginx Web Server for better WordPress performance

Moving a WordPress site from Apache to Nginx isn’t easy, but is well worth the effort – if you are on a micro instance and memory is at a premium.

kermit_memeI’ve written multiple posts about optimizing my blog to increase speed (here, here, and here)… unfortunately, my web server continues to crash at least once a day (usually due to a spike in traffic).

I started looking to stripping out unnecessary Apache modules, but had too many problems identifying the required modules for WordPress. After 30 minutes of failed server re-starts, I decided to ditch Apache all together and install Nginx as my webserver.

While Apache is the most well know WordPress webserver, Nginx is growing in popularity (WordPress.com uses Nginx on their site). In order to get a clean install, I created a new t2.micro instance, installed Nginx (and php-fpm) and migrated my WordPress files over 1.

There isn’t a lot of documentation on Nginx: I spent most of my time referencing the instructions at the following sites:

The install wasn’t smooth sailing. I had a beast-of-a-time getting my permalinks to work, and I forgot to change a few of my settings in my wordpress.php conf file (which caused my server to constantly crash).

There are still a few things I need to reconfigure – W3 Total Cache works differently in Nginx, so I’ve ignored it. I also have yet to re-install my certificates for https.

All that being said, my website is as fast as it was when I started my blog – probably due to Nginx, as well as the lack of “bloat” on the server (old WordPress plugins and no MySQL install).

My other call-out is that the use of AWS RDS and an Elastic IP made the most complicated parts of the migration simple.

Leveraging RDS to improve performance in the AWS Free Tier

Amazon-RDS[1]Six months ago, I created a Free tier account and got access to a t2.micro instance at no cost (for a year). My plan was to port my old blog over from Blogger (check), freshen up on my Linux skills (check), and to dip my toe into Lambda and DynamoDB waters (check and check).

errorestablishingadatabaseconnection-180x180[1]As the name implies – a micro instance is SMALL (1 vCPU, 1 GiB RAM). Naturally, a micro instance isn’t the most robust1. I was constantly having Apache crash, or getting the dreaded WordPress database connection error.

Fortunately, the Free tier also comes with 750 hours of RDS. So, following the instructions Pascal Alma’s website, I proceeded to move my WordPress DB instance from EC2 to RDS.

The move was straight forward…. with a few hiccups:

  1. I originally planned to use the AWS Database Migration Service, but had a heck of a time getting the endpoints to connect. After 20 minutes of fooling around, I gave up on DMS and instead used the export/import instructions in Mr Alma’s website.
  2. Security, Security, Security – make sure that you allow communication between your EC2 and RDS servers. I have my EC2 instances in one security group and my RDS instance in another, so I needed to alter the security group inbound rules to allow communication between the server (you’ll need this to both move the data and for ongoing operations).2

A few hours later (and honestly what should have taken 30 mins), I was running my blog against the MySQL database instance in RDS.

My only concern is cost; this blog is a hobby and I not looking forward to paying $100 a year for two t2.micro instances (webserver and DB). Maybe I’ll move the web server to a nano instance… food for thought.