How to optimize your web server and your WordPress blog

Monkey Working at MacBook

As regular readers may or may not have noticed, we had been struggling with server errors and crashes for quite some time. Rather than just throwing money at the problem and upgrading the server we decided to a do a little research and see if we couldn’t fix the problem. These tips are geared towards WordPress based sites but many will probably also work well with little to no modification on other types of sites but check with your local computer nerd first. Step one was to setup a new server from scratch, we used Digital Ocean’s one-click WordPress install but you can use whatever you want.

CloudFlare: Setting up a free CloudFlare account is by far the easiest, fastest and cheapest (free) thing you can do that will give you huge performance gains. It also helps to protect your site from hacking and DDOS attacks. Here’s what you need to do:

Step 1) Follow CloudFlare’s step by step instructions for creating a new account.

Step 2) Install the WordPress CloudFlare plugin.

Step 3) If you’re using Digital Ocean or any other hosting that is not pre-configured for CloudFlare, install mod_cloudflare for Apache. For detailed instructions visit this link and click on “Logging Real Visitor IP Addresses: mod_cloudflare for Apache httpd”.

Step 4) Follow this top notch tutorial by John Turner at SeedProd (no need to reinvent the wheel here) on how to supercharge your site by optimizing CloudFlare’s settings. If you have problems with the CloudFlare cache purge plugin or are otherwise having trouble seeing changes to your remember that you can always login to CloudFlare and manually purge the entire cache or a single URL.

Once CloudFlare has cached your site it should be incredibly fast, and incredibly fast from most locations worldwide. The results speak for themselves, just look at these test results from Dallas, Texas and San Jose, California! (Our server is in Europe by the way!)

Pingdom Speedtest from Dallas

Pingdom Speedtest from Dallas

Pingdom Speedtest from San Jose

Pingdom Speedtest from San Jose

It’s worth noting that CloudFlare is a content delivery network (“CDN”) and there are many other CDN options out there but CloudFlare’s ease of setup and low low cost of free make it the one to checkout first. If you want to look into other options just google it, there are tons of them.

Optimize Images: Most images for the purposes of websites can be compressed a lot. TinyPNG is a great tool to compress your images to the max without too much visible loss in quality. There are others as well like Kraken.io.

Optimize Apache: This can be a little confusing and a little daunting. There are so many different settings and so much geek jargon. Luckily there is an awesome tool for this called Apachebuddy. Just download the script, run it and do what it tells you. Just make sure to back up your conf files before making changes! Apparently there are other newer options to accomplish the same thing but this worked fine for me.

Optimize MySQL: Just like Apachebuddy there is a script that will do all the hard work for you called MySQLTuner. Get it. One caveat here is that you may not get accurate results unless you let MySQL run for more than 24 hours under normal server loads.

Set a Swapfile: This was covered under our server setup article but it’s worth mentioning again, this easy to do. Make sure you have a swapfile the same size as your ram. Here is an easy tutorial for Ubuntu, if you’re using something else google it!

Check Your Database: Make sure your database(s) are not fragmented or in need of repair. You can use the commands below but use caution, if you have large databases this can overwhelm your server’s resources, potentially for a long time.

mysqlcheck -uroot -p[password] –check –all-databases
mysqlcheck -uroot -p[password] –analyze –all-databases
mysqlcheck -uroot -p[password] –repair –all-databases (if necessary)
mysqlcheck -uroot -p[password] –optimize –all-databases

Enable Apache mod_status: This won’t increase performance but it will allow you to see the real time load on your web server at http://yourdomain.com/server-status. The steps to set it up may differ depending on your OS, google “how to enable Apache mod_status on [insert your OS and OS version]”. Here you can find instructions for Debian and Ubuntu.

Leverage Browser Caching: This starts to get a bit complicated but there are big performance gains to be had by setting this up correctly. You can find a detailed explanation here. If this is over your head technically just skip but if you have a computer nerd friend you can con into to helping you it’s a good idea to try to set it up. Remember to backup your conf and .htaccess files before you start playing with them. Here is set of recommended settings for WordPress. Don’t do anything you can’t undo!

Enable gzip Compression: CloudFlare will do this for you but if you’re not using CloudFlare you should set it up. Here is a good tutorial on how to enable gzip compression, in fact the entire site is great. Before doing anything you can check if you already have gzip compression enabled by visiting checkgzipcompression.com.

Minify HTML, Javascript and CSS: CloudFlare will do this for you but if you can’t use CloudFlare or don’t want to for some reason there are WordPress plugins that can do this for you. If you don’t want to use plugins you can checkout CSSMinifier and Javascript-Minifier.

Caching Plugins: Some people swear by either W3 Total Cache, WP Super Cache or Hyper Cache. These plugins do all kinds of stuff including minifying HTML, CSS and Javascript, caching, CDN support and more. The drawback is that there are tons of options and they are very complicated to setup (especially W3 Total Cache). It’s difficult to get them to work right if you don’t really know what you’re doing. Many people use these plugins with or without CloudFlare so if you can’t achieve what you’re looking for with any of the above you may want to look into these plugins.

Testing Your Progress: You can check the server load with the top command or at http://yourdomain.com/server-status if you set up the Apache status mod as recommended above. There are many free online tools for checking your page load speed, here are a few of the more popular ones:

Pingdom: http://tools.pingdom.com
Web Hosting Heor: http://www.webhostinghero.com
GMetrix: http://gtmetrix.com
Google Pagespeed Insights: https://developers.google.com/speed/pagespeed/insights/

Don’t be too concerned if you don’t get a perfect score or if you get what looks like a bad score on Google Pagespeed Insights. Take the advice and fix what you can fix but don’t worry about the rest, just do your best. Even google.com doesn’t get a great score on their own speed test tool as of April 2015. It’s almost impossible to get a perfect score.

Google.com on Google Pagespeed Insights

Google.com on Google Pagespeed Insights

Evaluate Results: If you’re scoring in the 90’s on most speed tests besides Google Pagespeed Insights you’re probably in pretty good shape. For the super geeks among us who are still not satisfied checkout, “Making your own WPEngine-Like High Performance WordPress Server“, that should keep you busy for a while.

Web Hosting Hero Speed Test

Web Hosting Hero speed test




You may also like...

%d bloggers like this: