Install HHVM, Nginx on Ubuntu 14.04 – Make WordPress Fly

In Development

Installing HHVM, Nginx on Ubuntu 14.04

Installing HHVM and Nginx on Ubuntu 14.04 is the next step in the “Make WordPress Fly” series. This tutorial assumes you have completed the prerequisites, read Part 1 and completed Part 2 of this guide. At this point you have a reasonably secure Ubuntu 14.04 VPS (if you don’t click the link to get one for $5) with MariaDB installed and configured. In this (Part 3) of the “Make WordPress Fly” guide we will start out by preparing our system for Nginx.

The first step is to reconnect to your VM via SSH.

Installing Nginx on Ubuntu 14.04

After reconnecting we are going to install some prerequisites in this order to make sure HHVM plays nicely with Nginx and WordPress.

After that process completes it is time to install Nginx. Installing Nginx on Ubuntu 14.04 is a very easy process. Ubuntu official repos come with a Nginx package but I prefer using launchpad repo maintained by Nginx team. We will also install the Naxsi WAF (Web Application Firewall) to provide some added security. You can choose not load Naxsi later as it slows down cached requests per second by around 3%. However, a full fledged WAF is worth a 3% requests per second hit.

If you prefer to use Nginx package in Ubuntu repo, you can simply run following command:

That concludes the process of installing Nginx. We will configure it further in later parts of this tutorial series based on whether you use WordPress Multisite or a single install.

Installing HHVM on Ubuntu 14.04

Let’s move on to installing HHVM on Ubuntu 14.04. We’ll need to prepare the HHVM repositories. Using sudo or as root user it is recommended to run sudo apt-get update and sudo apt-get upgrade first, or you may receive errors. Then we are ready to add the repositories and install HHVM.

Now that HHVM is installed there are a few simple configurations to apply. HHVM comes bundled with a script that makes setting it up with Ubuntu very easy.

If you are already using Nginx with PHP-FPM, you’ll have to modify the configuration file to disable the use of PHP-FPM. This file is normally located at /etc/nginx/sites-available/default

Look for the following section and make sure it’s all commented (by adding a # at the beginning of each line)

After doing this, execute the following script:

Executing this script configures Nginx to start using HHVM to process the PHP code. It’ll also restart the Nginx server so you don’t have to do anything else.

Then you may want to tweak the max_upload_size of HHVM by editing /etc/hhvm/php.ini. Otherwise HHVM is now setup and working.

Verifying that HHVM is Working Correctly With Nginx and Ubuntu 14.04

It is important verify that HHVM is working with Nginx. You can verify this by creating a file in /usr/share/nginx/html called test.php.

Paste this inside:


Visit to view the output. This will verify that HHVM is handling PHP. Now just make sure that HHVM and Nginx run by default at startup.

You are ready to move on to the next part of this tutorial.


Links to the Continued Guide “Make WordPress Fly”:

Preliminary – Getting Started with an Ubuntu VPS Running 14.04

Part 1 – HHVM, MariaDB and Nginx Make WordPress Fly – Intro

Part 2 – MariaDB Setup for Ubuntu 14.04 – Make WordPress Fly

Part 3 – Install HHVM, Nginx on Ubuntu 14.04 – Make WordPress Fly

Leave your thoughts in the comments below. Thanks for reading!


  1. Thanks for this but the prerequisite as well as installing Ubuntu and securing guides are giving a 404

  2. How do you create multiple sites with different ip’s, some how this works but when I try to add on a different ip in sites-available/default, it download’s the file when I try to hit index.php.

    • This is handled via DNS. You have to add the IPs as interfaces and the point the DNS at the IP you want traffic for that site routed through. You don’t need to specify IP in the Nginx config.

      • I’m trying to test it with ip’s before I point the dns to it, I have 2 ip’s on my vps, trying to let each go to different wordpress. I’m able to ssh using either ip’s, and able to read index.html files using different ip’s but when I try to use index.php, only on of the ip works the other just downloads the file.

  3. I get this error message when I try to install nginx-naxsi

    The following packages have unmet dependencies:
    nginx-naxsi : Depends: nginx-common (= 1.6.2-1+trusty0) but 1.6.2-2+trusty0 is to be installed
    E: Unable to correct problems, you have held broken packages.

    • you need to uninstall nginx-common ($ sudo apt-get purge nginx) and then install nginx version 1.6.2-1+trusty0 ($ sudo apt-get install nginx-common=1.6.2-1+trusty0). then you can get install nginx-naxsi. fun stuff eh?

      • Thanks, but I had to decide against using HHVM for now as it crashes too frequently and doesn’t support all the modules my WP Multisite needs.

  4. you need to uninstall nginx-common ($ sudo apt-get purge nginx) and then install nginx version 1.6.2-1+trusty0 ($ sudo apt-get install nginx-common=1.6.2-1+trusty0). then you can get install nginx-naxsi. fun stuff eh?

  5. Really a very Detailed Tutorial. Facebook’s HHVM is really good as it runs all the PHP scripts unlike Varnish which just provides Static HTML files. HHVM is better for Dynamic Sites while Varnish is better for Static Sites [I mean no regular changes]. Thanks again Bryan for this Awesome Tutorial

  6. Bryan,

    I’m attempting to setup a single WP site using these instructions and I get the following message in my Nginx error.log, any ideas? I’ve tried commenting out the MS config as well as the caching settings for @# and the other cache.

    unknown “skip_cache” variable



  7. I Have a really strange issue with HHVM, that it seems to append the DOCUMENT_ROOT to the end of the SCRIPT_FILENAME and PHP_SELF. I Really would just like to know if this is a common problem, as PHP5.4,5.5,5.6 & 7 don’t have this issue, and literally the only part I am changing is the port I run FPM over.

  8. Hello
    I had only one Q Why choose Ubuntu over CentOS.
    its not better CentOS 7 + Nginx + MariaDB + HHVM + Varnish + Redis ? or
    CentOS 7 + OpenLiteSpeed + MariaDB + HHVM + Varnish + Redis

  9. Works great, but only one problem. Permalinks don’t work. 404 error. Can you show your nginx.conf for WP?

Submit a comment