How to Install Nginx, HHVM and MySQL (LNMH) on Ubuntu
Edit Article

  • 1 Editor

This article gives a short description of Nginx HHVM and MySQL. This article will them define and explain the steps necessary to install all the above mentioned open source software on Ubuntu VPS Server on which we will then install WordPress HHVM so that it may run on it.



All of us must have heard of LAMP and LNMP, but nobody or mostly anybody would know what LNMH is. You must be wondering where the P went. The P that stood for PHP and where did it run off to. But more importantly you must be thinking about what the H part stands for Hack. Well not to worry. We’ve explained all and everything that you need to know in detail:

How To Install HHVM with Nginx on Ubuntu

HHVM:

HipHop Virtual Machine or simply HHVM is a process virtual machine. This process virtual machine works on the sole principle of Just In Time compilation (JIT).This is also used as an execution engine for the Hack Programming Language and for PHP as well. HHVM is developed by Facebook, the reason was that Apache+Zend combination was proven to not be as much efficient as wanted. It failed terribly on the comparatively large applications that were made on PHP. HHVM performed extremely well by proven serving more than a 9 times increase in web request throughput. Its performance was so brilliant that it consumed 5 times less memory for facebook, rather than the Zend PAHP engine + APC. Summarizing our whole talk, we’ll say this; HHVM is basically a virtual machine that is designed, developed and open sourced by Facebook so that it can execute and process scripts and programs that are written in Hack language and PHP. The best way to use HHVM is with a FastCGI based webserver like apache or Nginx.

Nginx:

Nginx, also pronounced as “Engine X” is a web server that has a strong focus on performance and minimum usage of memory. The other thing that it does is that it acts likes a reverse proxy server for HTTP, SMTP, POP3, HTTPS and the IMAP protocols. Other functions of Nginx include its use as a load balancer and a HTTP cache.


Nginx was created in 2002 by Igor Sysoev in 2002. This web server is compatible with UNIX, Linux, and BSD variants, Mac OS X, Solaris, AIX, HP-UX and Microsoft Windows as well. Nginx is free and open source software which was released under the terms of BSD-like license.

MySQL:

MySQL which is officially pronounced as (My-Ess-Que-Ell) and unofficially pronounced as (My-Sequel) is an open source RDBMS (Relational Data Base Management System). According to the survey conducted in January 2013 MySQL was considered the second most widely used relational Data Base Management System and the most widely used open source server-client model RDBMS. The name is thought of after the co-founder Micheal Windenui’s daughter. The SQL acronym in MySQL stands for Structured Query Language. MySQL is available in paid editions which offer more functionality.


PREREQUISITES:

  • Firstly, we’ll need a server that has Ubuntu installed on it (Vivid Vervet x64). Just so you know, HHVM is not compatible with any 32-bit operating system nor do they plan on adding any support for it. What helped me a lot in this tutorial was Digital Ocean. It lets you create a server and destroy it on an hourly basis so when I need to test something or write a tutorial like this one it almost costs me nothing.
  • A very basic knowledge of the commands used in UNIX.
  • A very basic knowledge about Putty or Terminal.
  • Something to drink like a cup of coffee or tea.

How to Install Nginx on Ubuntu

Step-1: You need to login to your server as a user that has root privileges (sudo). In case you are using a VPS from DO, you’d be asked to change your given password for the root.

1

Step-2:


Now you need to update all the packages and dependencies of your VPS. You can do that by simply giving it this one command:

apt-get update && apt-get upgrade –y

The screenshot Picture:

2

Step-3:


Now we need to give a command to install Nginx on your VPS. This will do the trick:

apt-get install nginx –y

It will look something like this:

3

Installing MySQL Server on Ubuntu

Step-1: By now you have installed Nginx as a web server on your Ubuntu VPS 15.04. So you will do now and install MySQL as your data base server. This server is actually needed by multiple scripts and apps like WordPress and joomla. To install MySQL server you need to issue this command:

apt-get install mysql-server -y

The installation won’t take much time and it’ll be done In a few second. You should see a screen similar to this one:

4

Step-2:


So when you have installed this you will need to setup a basic MySQL configuration which includes adding a password for you root user.

mysql_secure_installation

Building and installing HHVM on Ubuntu

Step-1: So now you have MySQL and Nginx installed on your Ubuntu VPS 15.04. Now comes the main part of this article which is installing the hiphop virtual machine on your VPS. For that to happen you need to install several commands that will download and install the package that is required for your HHVM installation:

  1. apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0x5a16e7281be7a449
  2. add-apt-repository 'deb http://dl.hhvm.com/ubuntu vivid main'

The picture for the above command result is added below:

5

Step-2:


You need to update the apt so that the new repository can now be applied:

apt-get update –y

It will look somewhat like this:

6

Step-3:


Now all you need to do is to just give a command to install HHVM on your VPS Server:

apt-get update –y

This shouldn’t take more than a few seconds and it should look like this:

7

If all works out right then you should see this message:

8

Step-4:


What needs to be done now s that you need to install and run the script that will install HHVM module for you Nginx. Give it this command:

/usr/share/hhvm/install_fastcgi.sh

After you’ve done so, you’ll see something like this:

9

Configuring NGINX Virtual host for HHVM:

Step-5


So let’s suppose that you want to add a new website. A website like example.com, so what you will do is that you will create a new virtual host file. For this purpose, any text editor can be used. In my guide I will do this using Nano:

nano /etc/nginx/sites-available/example.com.conf

Step-6


Copy the configuration made and past it there:

server {
listen 80;
server_name example.com;
include hhvm.conf;
access_log   /var/log/nginx/access.log;
error_log    /var/log/nginx/error.log;
root /var/www/example.com;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
}



When you have done all the editing, save and exit the editor that is in Nano:


Ctrl+O then Ctrl+X

10

Step-7


Now all you need to do is to make a web directory. Then you need to make some editing in the chmod and chown:

mkdir -p /var/www/example.com

chmod -R 755 /var/www/example.com

chown -R www-data:www-data /var/www/example.com

The picture is added below:

11

Step-8


In this step we enable our virtual hosts file that we newly created just by linking it:

ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/example.com.conf

Step-9


Now you know why I asked you to start with a cup of coffee by your side. Finally you go ahead and restart your HHVM and Nginx by these following commands:

service nginx restart

service hhvm restart
12

Step-10


Now to test what we have created. Let us create a test.php file and confirm if HHVM is working properly or not.

nano /var/www/example.com/test.php

Now add these lines of code in the file:

<?php

echo  defined('HHVM_VERSION')?'HHVM is up and working':'Sorry Not using HHVM';

?>

Picture is attached below:

13

Now to save and exit the file, hit Ctrl+O then Ctrl+X .


Step-11


And finally, open your web browser and after that just open the file that was newly created. And Voila!

example test page

HHVM IS UP AND WORKING!!!!!!

That is it. You have HHVM running on your Ubuntu server which is capable of handling PHP scripts. It runs them very fast and efficiently besides which will make your website run even even faster and smoother.

Article Tools

Did this article help you?

YesNo

Become
an Author!

Write an Article