I recently migrated 4CAST onto Amazon EC2, just to accommodate its future plans and features, and I completely ran into a lot of unexpected production issues. While the migration was pretty simple, the production issues were eating up my mind. I was easily spending over 32 hours fighting some issues running WordPress on Amazon EC2, and if you’re reading this, I don’t want you to waste huge amount of time fighting all these.
Now, let’s look at how to solve the first major issue, which is the images does not resize after you migrate your existing blog to Amazon EC2.
Fix Images not resizing automatically in WordPress on Amazon EC2:
Amazon EC2 is great. But it is just a OS running on a server and nothing like the platform you get on a Shared hosting. After you successfully install Apache, mySQL, PHP and such on the Amazon EC2, and then you migrate the existing WordPress DB into your new server, and the site would be up and running, and that’s when you start to think that everything is working just fine. But wait, there’s more.
Once you migrate the DB to the new server, you’ll be happy, and you’d just think of giving it a go live for the site. But the real problem would come into light only when you publish a new blogpost on the new server, with a featured image. The images would get uploaded, the post would be ready, and the featured image will even work on the preview post page. But then, once you publish the post online, the homepage, where the new post would get listed, will NOT load completely.
I was looking for some bug in the theme, my installation, and even moved it into a new instance. But the search was in vain. There’ was another problem, which was comfortably sitting which I did not even know. Which is, I failed to understand how the images are actually cropped and resized.
WordPress uses a library called PHP GD library. The library is the one which actually resizes the images, and gives back to the WordPress wp-content/uploads folder. And sadly, the Amazon EC2 does not come with a default PHP GD library in it.
So the solution? It’s pretty simple. Just install the PHP GD library on Amazon EC2 with WordPress. Here’s how you could install it with ease:
- SSH into your instance
- Type
sudo su
- Now, run
yum install php-gd
- Restart Apache:
service httpd restart
- Restart mySQL:
service mysqld restart
And that’s it. You’re done. Just upload the new images, and you’ll be good to go!