Whip-Snapping Fast WordPress with Nginx and HHVM-Part 3

Smoking Server
I love it when a post comes together.
Ok, folks, here’s where it all comes together to finally get our HHVM/Nginx server spitting out some really fast WordPress.

So in our last episode, our heroes (that’s us) installed Nginx and HHVM to get php going on the server…Now we’re almost ready to install WordPress, but first we need to install our database.

MariaDB: a database by any other name

WordPress was made for MySQL. MySQL has been a good, reliable and relatively simple database to use for decades. That’s why we’re going to be installing MariaDB.

What’s that? Why not MySQL? Well, there’s not exactly anything wrong with MySQL per se. It works the same way it always has. However, since Oracle bought MySQL and took over, a lot of the open development has become, well, less open. That’s when Monty Widenius, the original founder of MySQL, forked MySQL to create a binary-compatible system called MariaDB. Since then, most of the open source community involvement has focused on MariaDB. In practice, over the last couple years, we’ve seen a few security holes patched much faster on MariaDB than on MySQL.

One last thing, MariaDB comes in two flavors. There is the 5.5x series, which mirrors the MySQL current stable. Then there is the 10x series. The 10x series was created to begin implementing fun new features that aren’t likely to make it into MySQL anytime soon. For our purposes, we want the 5.5x.

Head over to MariaDB’s repository configuration tool and step through to pick your linux flavor and versions so they can pick a mirror near you. Or, just pop the following in your terminal:

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://mirrors.syringanetworks.net/mariadb/repo/5.5/ubuntu saucy main'

And then…

sudo apt-get update
sudo apt-get install mariadb-server

It’ll ask you to set up a root password for MariaDB. Make it a good one.

Now that that’s done, let’s log into our MariaDB server and set some things up.

mysql -u root -p

Feed it the password you just set up two paragraphs ago when it asks and you’ll be logged in. Now we’re ready to create a database for our WordPress site.

CREATE DATABASE mysiteblogdbname;

Now create a user to go with your database, with the permissions needed on the new db.

GRANT ALL PRIVILEGES ON mysiteblogdbname.* TO "wordpressusername"@"localhost" IDENTIFIED BY "reallycleverpassword";

Done with the database for now. Let’s close up shop.

quit;

And now…for WordPress

First thing we need to do is get WordPress. Let’s grab the latest from their server.

wget http://wordpress.org/latest.tar.gz
tar -xvf latest.tar.gz

That’ll grab the most recent code from WordPress and unzip it to a folder ‘wordpress’ in your current directory. Move all of the files in that directory to your web site root.

sudo mv ./wordpress/* /var/www/sitename.com/public

Now let’s copy the WordPress sample config and place our database config values inside.

sudo cp /var/www/sitename.com/public/wp-config-sample.php /var/www/sitename.com/public/wp-config.php
sudo nano /var/www/sitename.com/public/wp-config.php

Add in your database values for DB_NAME, DB_USER, and DB_PASSWORD in the config file. Leave DB_HOST as localhost. Save the file.

One More Thing…

Great news! As of WordPress 3.9, the following hack should no longer be necessary. Nothing to see here. Move along.

There’s one tiny tiny little change you need to make to WordPress to get it to play nice with HHVM. It’s 99.9999% fully compatible. But there is one spot where the WordPress database setup defines a case-insensitive constant. This is something that is apparently done for backwards compatibility with older plugins. In any case, we need to open up the file:

sudo nano /var/www/sitename.com/public/wp-includes/wp-db.php

And change the following line …

define( 'OBJECT', 'OBJECT', true );

To the following 3 lines…

define('OBJECT', 'OBJECT');
define('Object', 'OBJECT');
define('object', 'OBJECT');

Now the bad news is that, whenever you update your WordPress engine, you will have to edit that same file and change that same line. Don’t let that discourage you from updating though! The good news is that should only take 10 seconds.

Now load up your home page in a browser and be greeted by WordPress’s famous Five Minute Install screen. Answer some questions and you’re ready to sling some wicked prose on your new super fast WordPress blog.

There’s more we can do to make things run smooth, speedy and secure, so stay tuned for the next installment!

2 thoughts on “Whip-Snapping Fast WordPress with Nginx and HHVM-Part 3”

Leave a Reply

Your email address will not be published. Required fields are marked *