How to Install Nginx, HHVM and MySQL on Ubuntu 15.04 (LNMH Stack)

Sunday, May 24th 2015. | how to

#howto ,#tutorial #VPS – How to Install Nginx, HHVM and MySQL on Ubuntu 15.04 (LNMH Stack) – This tutorial explains step by step guide (with pics) about How to Install Nginx, HHVM and MySQL on Ubuntu 15.04 (LNMH Stack)

install-hhvm-ubuntu-vps

We knew and heard a lot about LAMP and LNMP, but what about LNMH stack? Wait what? Where is the P part that stands for PHP? Where does it go and what is the H part there? Meet HHVM, an open-source virtual machine designed for executing programs written in Hack and PHP. Early, HHVM is developed by Facebook because the regular Zend+Apache combination is not as efficient to serve large applications built in PHP. It performs very well and proven serving over a 9x increase in web request throughput and over a 5x reduction in memory consumption for Facebook compared with the Zend PHP engine + APC. Shortly saying, HipHop Virtual Machine (HHVM) is a virtual machine developed and open sourced by Facebook to process and execute programs and scripts written in PHP and Hack language. HHVM can be used together with a FastCGI-based webserver like nginx or apache.

In this article, we’ll try to learn how to install Nginx web server, MySQL and HHVM on Ubuntu 15.04 VPS which then we can install WordPress to run on it. A tutorial with pictures.

Prerequisites

  1. A server (vps, cloud, dedicated) running Ubuntu 15.04 Vivid Vervet x64. For your information, HHVM doesn’t support any 32 bit operating system and they have no plans to add support for 32 bit operating systems. In this guide I use a droplet from Digital Ocean with 1GB RAM that costs $10/month but for this tutorial I spent only $0.030 (2 hours). That’s what I like from DO as they charge hourly so I can simply create a server and destroy it every time I want to write a tutorial or test something. You can see my setup to create a droplet at DO here.
  2. Some basic knowledge of common Unix command.
  3. Some basic knowledge about Putty (Window) or Terminal (Linux).
  4. A cup of coffee or tea.

How to Install Nginx

Step 1 – Login to your server as root or as a user with root privilege (sudo). If you are using a VPS from DO, you should be also asked to change given root password.

login-root-ubuntu-hhvm-tut

Step 2 -Update all packages and dependencies of your VPS with this magic command:

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

screenshot pic:

upgrade-dependencies-packages-hhvm

Step 3 – Issue this command to install Nginx on your Ubuntu 15.04 vps easily:

apt-get install nginx -y

It looks similar like this:

install-nginx-hhvm

How to Install MySQL

Step 1 – So you have Nginx installed as web server. Now you can proceed to install MySQL database server which is generally needed by many scripts / apps including WordPress and Joomla. Issue this command:

apt-get install mysql-server -y

The installation should be done in seconds:

install-mysql-hhvm

Step 2 – Once installed, you will then need to setup basic MySQL configuration including to create new password for MySQL root user.

mysql_secure_installation

screenshot (click it to see larger version):

mysql-config

How to Install HHVM

Step 1 – So you have Nginx and MySQL in place. Now let’s enter to the main menu which is to install HHVM on your vps. But firstly you have to issue several commands to download the required HHVM package.

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

pic:

download-key-server-ubuntu-hhvm

Step 2 – Do apt-get update so the new repository can be applied:

apt-get update -y

it looks like this:

apt-get-update-hhvm-repo

Step 3 – Finally use this command to install HHVM on your VPS:

apt-get install hhvm -y

the process should finish in seconds:

install-hhvm-on-ubuntu

If the process gone well, you should also see this welcome message:

hhvm-installed

Step 4 – Now you have to run the install script that will install HHVM module for Nginx. Issue this command:

/usr/share/hhvm/install_fastcgi.sh

you’ll see something like this:

configure-hhvm-nginx

Configure Nginx Virtual Host for HHVM

Step 5 – Assuming you want to add new website called example.com, so create new virtual host file. You can use any text editor but in my guide I use Nano:

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

Step 6 – Then copy paste this configuration 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; 
    }
}

Once done editing, simply Save and Exit the editor which is in Nano: Control+O then Control+X.

nginx-hhvm-conf

Step 7 – Now create your web directory and do some chmod and chown-ing stuff:

mkdir -p /var/www/example.com
chmod -R 755 /var/www/example.com
chown -R www-data:www-data /var/www/example.com

pic:

create-web-directory-nginx

Step 8 – Now enable your newly created virtual hosts file by linking it:

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

Step 9 – Finally restart Nginx and HHVM:

service nginx restart
service hhvm restart

illustration:

2015-05-24_220811

Step 10 – Now give it a test, create a test.php file to confirm if HHVM is running and working:

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

then put this in that file:

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

pic:

test-hhvm-running

Hit Control+O to save then Control+X to exit the editor.

Step 11 – Now open up your browser and open the newly created HHVM test file and Voila!!

hhvm-is-working

That’s it and congratulation you now have HHVM running on your vps and is capable to serve PHP scripts much more faster and efficient plus Nginx on top of that so your website will now faster.

This post How to Install Nginx, HHVM and MySQL on Ubuntu 15.04 (LNMH Stack) is part of ServerMom.

Source link