Installing HHVM on Ubuntu

. 2 min read

I tried install HHVM for fun on my Ubuntu machine using the following steps:

  • Check ubuntu version
lsb_release -a
  • Add the offical repo

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0x5a16e7281be7a449
sudo add-apt-repository "deb http://dl.hhvm.com/ubuntu $(lsb_release -sc) main"

I work out a fish shell, so had to type bash to get into a bash shell before running the above commands. Didn't spend time to customize fish to use bash commands

  • Install HHVM
sudo apt-get update
sudo apt-get install hhvm
  • Add HHVM to Startup
sudo update-rc.d hhvm defaults
  • Configure NGINX to use HHVM

On my home machine, I don't have any custom FastCGI configuration, so the below default integration of Nginx with HHVM will work. Else, look at the DigitalOcean link below.

sudo /usr/share/hhvm/install_fastcgi.sh

This basically adds the configuration file /etc/nginx/hhvm.conf to the default Nginx server block configuration /etc/nginx/sites-enabled/default. It works only with a default Nginx configuration without any FastCGI configurations.

  • Configure HHVM to listen on a socket

As the DO link states, HHVM is considered for environments under heavy load so the first configuration change you can do is to make HHVM listen to a socket instead of a TCP port. Thus, the communication between Nginx and HHVM will require less CPU and memory.

To do this edit, /etc/hhvm/server.ini using:

sudo vim /etc/hhvm/server.ini

Remove the line starting with hhvm.server.port and add the below line:

hhvm.server.file_socket=/var/run/hhvm/hhvm.sock
  • Configure Nginx to use the socket

For this we need to edit, /etc/nginx/hhvm.conf using:

sudo vim /etc/nginx/hhvm.conf

Change the fast_cgi pass line to:

fastcgi_pass unix:/var/run/hhvm/hhvm.sock;

Restart NGINX

sudo service nginx restart
  • Test HHVM!

Edit the Nginx default file:

sudo vim /etc/nginx/sites-enabled/default

Then go to the server part and add index.php at the line with indexes so that it looks like this:

index index.html index.htm index.php;

Restart NGINX

sudo service nginx restart

To make sure HHVM is being used and not the legacy version of php, run:

/usr/bin/php --version

My output is:

HipHop VM 3.10.1 (rel)
Compiler: tags/HHVM-3.10.1-0-g689b4969a141620ee5a282ce0dbf72278c84d44b
Repo schema: 6c99ee1f98340f6f3ef397a332583f0e843a627d

If the old version of php is being used, update using the following command to make hhvm be used by running:

sudo /usr/bin/update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60

Now let us do the standard phpinfo() test! :-)

Create the index.php file:

sudo vim /usr/share/nginx/html/info.php

Enter the following lines:

<?php
phpinfo();
?>

Set the permissions, as it is always a good practice to make sure that all Nginx web files are owner by the Nginx user www-data. Thus change the ownership of this file to www-data with the command:

sudo chown www-data: /usr/share/nginx/html/info.php

Access the link using ... http://your_server_ip/info.php

  • Make HHVM start on boot

Important! HHVM doesn't start on boot(currently). To make it start run use:

sudo update-rc.d hhvm defaults

You can always check it using:

sudo service hhvm status

Yay! It works! My output is below! :-)

HHVM PhpInfo

References


Tags

AWS Analytics Antifragile Apache Spark Apple Apps Arbitrage Automation Awesome BBMP Bangalore Black Swan Bonds Boonex Bootstrap Brokerage Charges CFPB CMS CSS Calypso Camelot Capital Markets Charts Chirp Choropleth Chrome Code Igniter Collections Containerization Converters Cycling DalalBeat Data Analytics Data Journalism Data Mining Data Munging Data Privacy Data Science Databases Debt Design Design Stock DesignStock Diet Django Docker Document Processing Dropbox Electron Electronics Entertainment Entrepreneurship Exercise FFMPEG Facebook Finance Fire TV Stick Fitness Forerunner From-The-News Fun Futures Gaana Garmin General Geocoding Getting Started Ghost Google APIs GraphicsMagick HHVM HTTPS Hackathon Hacks Hardware Health House Keeping Housing IBM BlueMix IBrokers IPinfo Ideas Image Conversion Image Processing Infographics Interactive Brokers Internet Investing IoT Legal Lets Encrypt Mac Machine Learning Mailbox app Mapbox Markdown Marketing Meteor Mockups MongoDB Mortgages Movies Music MyPad MySQL Nativefier Nature Netflix Newsletters Nginx Node.js Notes OCR OSX Open Source OpenCPU Options PDF PHP Pebble Peloton Personal Photography Picture Platforms Plex Portable Apps Productivity Property Tax PyroCMS Quantitative Finance R-Project Random Raspberry Pi Research Resources Reticulate Robot S3 SQLite STT Scraping Security Server Shell Shiny Side Project Sikuli Speech Recognition Spider Pro Spinning Spotify Startup Resources Startups Strategy Sublime Text System Monitoring Tax Terminal Tips To Do Tools Torrent Trading Trends Troubleshooting USElection2016 Ubuntu Unix Valuations Video Conversion Visualization Wagtail Wearables Weekend Fun WhatsApp Wordpress anaconda annie bash catalina cv2 daily coding dailycoding data.table debugging devtools downloader e-Signatures ggplot git go google maps hat-tip iOS iPad iPhone iTunes javascript jupyter logging macos numpy opencv optionality plotly python rstats videos youtube