WordPress on VPS with Nginx and PHP APC
It was time to pay the yearly fee for shared hosting and I decided to check out some VPS options. Performance was not really a problem as WordPress caching plugins do a good job but I wanted more control of the stack and VPS pricing is not that far off from shared hosting. DigitalOcean plans start at 5 dollars and you get 1 Core with 512MB Memory, 20GB SSD Disk, and 1TB of Transfer. You can setup a droplet in 1 minute and you can pay month to month. No wonder they are doing so well, it makes sense to just try them out. They also have great documentation, API, and an easy to use control panel. Here are some details on how I moved my WordPress blog from shared hosting to VPS and made it really fast with Nginx, PHP APC, and Super Cache.
At first thought, I wanted to play around with Go Lang so I followed the instructions for a simple server setup on Ubuntu and a tutorial on running Nginx as a reverse proxy for Go. I’ll write more about Go Language in other posts but this setup allowed me to quickly follow up with LEMP and WordPress install on Nginx. That part was easy and quick.
Since I needed to move over my plugins and themes, I decided to setup FTP via vsftpd. Install was easy but I ended up spending some time on figuring out how to set proper permissions correctly and had to read up on chown and chmod. I also had to fix this 500 OOPS: priv_sock_get_cmd error and allow FTP access to my development folders like the WordPress plugins and themes folder.
At this point I was ready to export my blog content and this gave me an opportunity to remove spam comments and crazy amount revision history of posts in the database. These WordPress SQL queries have been really helpful. Importing all the posts into my new SQL server failed with a “413 Request Entity Too Large” error. I found a fix and moved onto setting up APC Object Cache via: apt-get install php-apc. To use the PHP opcode cache, I installed the WP APC plugin and then I installed WP Super Cache. Things have definitely improved but I really felt a difference when I tuned up the mysql, PHP-FPM, and nginx configuration files. This took some time as the variables depend a lot on your machine/droplet (number of cores, memory, etc) and your application needs. Here are some good config optimization articles:
Optimizing Nginx for High Traffic Loads
Nginx Performance Tuning
Optimizing Nginx Configuration
High performance web server with Nginx and PHP-FPM
HTTP Cache and gzip on nginx
10 Million hits a day with WordPress
I think I tuned it up pretty well because the blog is speedy and I saw major improvements in comparison runs on WebPageTest. As a result of this process, I ended up on a much better environment, hosting WordPress with much better performance, and I also learned a bunch of stuff. It was a good time to update WordPress to the latest version and learn some mysql. You end up configuring a lot of things on your own, which does burn some time, but it also allows you to understand all the parts of the system much better and gives you more power.
Keep in mind that things like a mail server or things like phpMyAdmin would also need to be installed if you want/need it. Personally, I can do with less mail and prefer mysql command line. Next, I am going to look into Varnish and CDNs.