Because I outgrew shared hosting, I needed to go the next step up and decided to get an unmanaged VPS with Linode. I really wanted to be able to set it up so well that I wouldn’t need to migrate or upgrade server for a very long time, so I needed it to be high-performance. I defined performance as maximizing the number of successful requests/s while minimizing the usage of server CPU and RAM (whenever I mention performace in this post, this is what I mean).
After much research for setting up and running a VPS for WordPress, I decided to go for this setup: Apache worker + PHP 5.5 + Varnish on Debian.
This post is really more of a reminder for me to remember what I did and why. With every step, I benchmarked and experimented further, however please note that when I started doing this, I was keen on benchmarking server performance with newrelic and load testing with loader.io. After a while, I realized I was hitting the cap of my 1GB Linode plan for 125 Mbit Network Out (so no matter what I changed, the server just wouldn’t permit load testing downloads of more than 125 mbits/s [or 15.6MB/s]). So all my tests cap’ed out and my benchmarking went away. Maybe one day I’ll do the same tests on DigitalOcean or some other host without such caps…
1. Set-up linode VPS. Follow along with their documentation. Secure VPS and optimize as per their tutorials.
2. Optimize further using Configuring Apache/PHP/MySQL for Low Memory (RAM) VPS as a guide. As awesome as PHP APC is, I later ditched it in favor of PHP FPM. Disable unnecessary Apache modules by doing commands such as:
sudo a2dismod autoindex sudo a2dismod reqtimeout
Experiment / load test with different prefork settings for performance.
3. Apache Worker + mod_fcgid
Using How to increase the performance of a WordPress site with Apache worker mpm as a guide, I tested out Apache Worker + mod_fcgid. But I couldn’t get it to work better than plain old prefork.
Don’t keep these changes. Restore server from a full backup.
4. Apache worker + php fpm + fast cgi
Next, test using PHP FPM + fast cgi. Installing both did not successfully complete because libapache2-mod-fastcgi was not in sources.
So add to /etc/apt/sources.list:
deb http://http.us.debian.org/debian wheezy main non-free
Proceed to install
sudo apt-get update sudo apt-get install libapache2-mod-fastcgi php5-fpm
Then follow Apache2 MPM Worker with PHP-FPM and optimize!
5. Install W3 Total Cache
I couldn’t improve performance anymore, so installed a caching plugin to do disk cache and minimize. Performance increased by more than 250%!!
6. Upgrade to PHP5.5, Debian 7.6, update and upgrade everything
Debian was unable to upgrade anything further, so add dotdeb as a source. Here’s how.
The upgrades alone led to less standby RAM and increased PHP performance.
7. Add a PHP cache
APC is not supported anymore and thus it can’t be installed. Try memcache.
sudo apt-get install memcached php5-memcache
8. Configure W3total cache with different settings
Experiment with different cache types and settings to find the one that gave the best performance. I ended up using the following scheme:
Page cache method: enhanced
Minify method: disk
Database cache method: none
Object cache method: memcache
9. Add varnish
Varnish is awesome!! It turned my average load times of 264ms to 34ms. Craaazzzzyyyyy!!
The main reference I used is Making WordPress Faster with Apache, Varnish and W3 Total Cache on Amazon AWS EC2 with CloudFront CDN.
I got some changes for /etc/varnish/default.vcl from here and ended up making even more changes to it. This is the default.vcl I ended with, which contains some lines added to obscure-ize things about my server: varnish default.vcl.
10. increase memcached max memory
I noticed a small amount of thrashing which I believe was memcache going to swap, so I increase memcached max memory to 128mb.
In /etc/memcached.conf change the applicable line to
Then restart the memcached service.
11. Add Pure-FTPd
So that WordPress can install plugins, upgrades, etc… Used http://articlebin.michaelmilette.com/setting-up-pure-ftpd-in-ubuntu/ as my main guide.
That’s it for the most part.
In the future am going to remove PHP-FPM. I really don’t need it. I have very few WordPress users and normal web visitors will see everything cached. Am also using CloudFlare on top of all that.
So websites in my VPS are accessed thru these layers: visitor’s browser > CloudFlare > Varnish > W3 Total Cache > WordPress
UPDATE: Discovered OpenShift. Their free tier is pretty awesome. In the name of trimming costs, I’m moving everything away from Linode and will go back to a VPS when/if I outgrow OpenShift.