How to install NGINX and HHVM with PHP5-FPM Fallback on Ubuntu 16/14

Diego Rodríguez Baquero
HackerNoon.com
2 min readJan 19, 2017

--

In this tutorial I will be guiding you with steps to install NGINX stable, HHVM 3.9 and PHP 5 FPM.

  • Nginx is a great webserver or reverse proxy that comes with a default configuration much faster than Apache 2.4 with its default MPM (Prefork).
  • HHVM is a virtual machine that uses JIT (Just in time) compilation aproach.
  • PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.

A little setup background:

  • Clean KVM Machine with Ubuntu 16/14 LTS with 1GB RAM and 1 CPU Core from Vultr (Less than 1GB RAM will cause you trouble if you bundle MySQL)
  • Root access (Else you must do sudo [command])

First, Nginx:

Second, HHVM:

We want to run HHVM on a Unix Socket, so let’s edit it’s configuration:

Comment “hhvm.server.port = 9000” with ; and add “hhvm.server.file_socket = /var/run/hhvm/hhvm.sock”

It should look like this:

Save with Ctrl + X and then ‘Y’

Now PHP-FPM:

This should install FPM and listen on /var/run/php5-fpm.sock by default

We are done installing! Let’s configure things now. Let’s start by creating a upstream conf file for nginx:

Add the following and save:

As you can see, PHP-FPM will be a backup in case HHVM fails.

Now let’s edit Nginx’s HHVM conf file:

Replace “fastcgi_pass 127.0.0.1:9000;” with “fastcgi_pass php;” . It should look like this:

Restart the services with:

Test with:

Should be a 404 (As the actual test.php doesn’t exist) with these headers:

And that’s all! We have latest stable Nginx with latest HHVM in fastcgi with php-fpm fallback!

Hacker Noon is how hackers start their afternoons. We’re a part of the @AMIfamily. We are now accepting submissions and happy to discuss advertising &sponsorship opportunities.

To learn more, read our about page, like/message us on Facebook, or simply, tweet/DM @HackerNoon.

If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!

--

--

Diego Rodríguez Baquero
HackerNoon.com

Software Engineer 💻, MSc. SE Student 🎓, FOSS Collaborator 💙