How to Install Nginx, HHVM and MySQL on Ubuntu 15.04 (LNMH Stack)
| |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
- 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.
- Some basic knowledge of common Unix command.
- Some basic knowledge about Putty (Window) or Terminal (Linux).
- 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.
Step 2 -Update all packages and dependencies of your VPS with this magic command:
apt-get update && apt-get upgrade -y
screenshot pic:
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:
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:
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):
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:
Step 2 – Do apt-get update so the new repository can be applied:
apt-get update -y
it looks like this:
Step 3 – Finally use this command to install HHVM on your VPS:
apt-get install hhvm -y
the process should finish in seconds:
If the process gone well, you should also see this welcome message:
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 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.
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:
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:
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:
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!!
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.
Have you ever test it on live blog/web? I heard HHVM still unstable and need to be restarted when crashed.
No I never but I want and I will test it on live blog (but not for production) coz I’m also curious of it. So far I know only Facebook use it for production. I also heard that WPEngine developed mechanism so if HHVM fails it will revert back to PHP 5.
Thanks for this. I have sweated blood trying to get this combination up and running and yours is the first tutorial that worked! Would like to see more around the configuration the various files, particularly the tightening up the security of the config. Thanks again
Glad knowing it works for you
Hi Sawiyati,
Thanks for all these wonderful tutorial, I went through this entire tutorial, You have also included screenshot about how to create a Droplet, that’s really great. If you could include steps on how to setup DNS in Digital Ocean that would be really helpful as this would complete everything that would be required to build the server on Digital Ocean.
As always a wonderful writeup! I followed the guide and everything seems to work fine. One problem I’m running into though is that php-files are not being executed. It just displays the code of the file (in IE) or tries to download the file (Chrome). Am I missing something?
Nevermind, I redid the whole thing (installed MariaDB instead of MySQL) and for whatever reason now it’s working fine. 🙂
bu request tutorial install dan konfig nginx + hhvm di centos 7 dong, terima kasih ….