/ HHVM

Installing HHVM on Ubuntu

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