For some time now I wanted to tell you about
Hip Hop Virtual Machine
best known for its abbreviation
. It is not a music group but a virtual machine designed by Facebook for their own use but they have released the code so we can all use it.
HHVM supports PHP and Hack
, the latter being a new PHP-based programming language that gives us new features such as the use of collections (alternatives to PHP arrays), static typing, allows the use of Lambda expressions, etc. … How it is not the objective of the article to speak in depth about the Hack language you can visit the
with all the information (in English).
The main feature of HHVM is that it has a JIT (just-in-time) compiler.
To explain it simply, HHVM compiles PHP (or Hack language) in bytecode and then this bytecode is translated into machine language using the JIT compiler. The compilation process described allows various optimizations to be performed and thus increase the performance of our PHP applications. If you want to know more about HHVM, it is best to visit its
Before continuing I should also clarify that the configuration I show in this tutorial on how to install HHVM in Ubuntu,
is not intended for servers in production
HHVM installation guide on Ubuntu 14.04 x64 with Apache
The first thing will be to describe the work environment we are working on so you can replicate it. The tests have been performed on a
DigitalOcean VPS with
512MB of RAM and with the Ubuntu 14.04 x64 operating system. I must clarify that
HHVM only works on x64 operating systems
, so do not use a 32-bit operating system because it will not work.
The version of Apache installed at the time of writing the tutorial is Apache 2.4.7, which we installed apt-get by default
(later I describe how to do it)
Installing Hip Hop Virtual Machine from scratch.
Once we access our server through SSH with PuTTY for example, we have to execute the commands described in the
, which are the following for Ubuntu 14.04:
wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -
echo deb http://dl.hhvm.com/ubuntu trusty main | sudo tee /etc/apt/sources.list.d/hhvm.list
sudo apt-get update
sudo apt-get install hhvm
At this point HHVM is already installed and we must install Apache, for this we execute the following command:
sudo apt-get install apache2
When the installation process is finished we must configure Apache and HHVM to work together, to achieve this we execute the commands:
sudo /etc/init.d/hhvm restart
sudo service apache2 restart
At this point we will do two tests to verify that everything has gone well. First we execute the
command and something similar to:
Repo schema: 0e12aaa31fae66b5591f65603de50c9d62caafac
Extension API: 20140829
The second will be to access our Apache server to verify that it is working. For this we must put the IP in our browser as follows:
, for example,
During the previous HHVM configuration a file is created that causes a 404 error when we try to access php files.
The solution is to delete this configuration file with the following command:
sudo rm -rf /etc/apache2/mods-enabled/hhvm_proxy_fcgi.conf
Now we edit the Apache configuration file with the command:
We move to the directory configuration section and enter the line:
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1
It has to be as seen in the image (for more advanced configurations consult the
Restart Apache and with this all files with PHP extension will pass through HHVM.
sudo service apache2 restart
To prove that it really works, we create a test php file and then access it:
We add the line:
<?php phpinfo(); ?>
We access the php file through the browser:
I hope the tutorial has been helpful and if you have any questions, do not hesitate to use the comments.