PLEASE NOTE: This post was originally created in 2011 and some of the processes and plugins mentioned may no longer be correct or available.
Recently I’ve been tasked with management of a couple of WordPress websites that get more traffic than I’m used to dealing with. Quite a bit more in fact. So much so that they were causing the server they lived on to have memory issues, random reboots and other odd issues.
In order to get the sites more stable, I started clearing out plug-ins. Starting by deleting the ones that were being used and actually deleting them off the server. Then removing plugins that weren’t really needed and replacing them with a WordPress function where possible.
Result: Not enough to stablize the server
Result: Better, but server still not 100% stable.
Looking at the remaining plugins and with help from support, the next culprit was the NextGen Gallery plugin. This is a key component on each site and disabling it actually was a bad thing. But I had a server that was rebooting itself every day, so disabling it I had to do.
Support was also able to temporarily upgrade the server (it’s a virtual server, so easy for them to do).
Result: Stable server!
Needing to allowing more hotlinking than I had setup, NextGen gallery support and to improve the overall speed of the sites, it was time to look for solutions. It was recommended to look at using a Content Delivery Network (CDN) like Rackspace or Amazon S3. Having not used a CDN before, I figured it was as good a time as any to give it a whirl, and I decided (based primarily on price) to use Amazon S3.
Starting here at donburnside.com.
The google pointed me at a few plugins that have been crucial in making the switch to S3 possible.
- Creating a CNAME DNS entry for the S3 bucket.
- WP Super Cache. Some recommended W3 Total Cache, but I read it gave memory errors on occasion (a problem I was trying to escape) and Super Cache was already installed on both sites
- Amazon S3 for WordPress. What this does is take anything that is uploaded using the WordPress media uploader and automatically moves it into the S3 bucket of my choosing.
- CDN Sync Tool. While it acts weird on my server because a depreciated piece of PHP is missing, I was still able to make it work to get all of the data needed over to the Amazon S3 bucket and keep them updated, kind of.
Starting with the CNAME entry, I mapped it to an identically named S3 bucket. This is needed to make sure everything works correctly. The CNAME entry is required for the Amazon S3 plugin to work correctly.
Once that was setup, I used CDN Sync to get all of the necessary files to the bucket. It’s also used to keep certain directories updated, like the gallery directory. That part happens manually which I will discuss later.
Finally, turning on CDN support in Total Cache. This redirects any call to any folder specified (wp-content and wp-includes are default) to the CNAME’d entry that I previously specified.
Done and done. WordPress, within a few hours, running from a CDN. Since I’ve not done this before, it took much longer than a few hours. Now that I know how easy it is, it won’t next time.
NextGen Gallery + Amazon S3
Currently, there is no support for any CDN within the NextGen Gallery Plugin. This is a problem because, like I mentioned, the sites rely heavily on that plugin. Some more googling brings me to this thread at the WordPress.org support forums offering a hack to redirect the plugin to look at the S3 bucket I needed. And it works very well with 1 minor hitch. Hacking a plugin to work outside of it’s normal parameters means with the next update, your hack will be gone. So I created a duplicate of the file that I modified so I can replace it (or duplicate the hack) after an update.
Once that is done, when you upload images to the gallery they go into the gallery folder on the server just like always, but you can’t see any of the images or thumbnails since they are being referenced back to the CDN. That means that once a gallery is created and images are uploaded, you have to go back into CDN Sync Tool and run a sync on the
wp-content/gallery/[directory name here]. That will move all of the images and thumbnails to the CDN and you can post the gallery, serving images from the CDN.
Now I have sites that are not only running faster than before, but they are using half as much bandwidth from the hosting company and fewer resources (all js and css files are also being served from the CDN). And, at least on Amazon, for not very much cost. On 2 sites that get approximately 175K views per month, the cost is going to be about $30 or less, and the bandwidth savings on the server is close to 75%!
If you are looking for a way to speed up a site or reduce the load on a server, I can not recommend this enough.
Comments are open if you have any questions!