Tutorial: How to install Facebook’s HHVM on Ubuntu 18.04
HHVM is an open-source virtual machine designed for executing programs written in Hack and PHP 5 and 7. It achieves superior performance compared to the Zend Engine by utilizing a just-in-time (JIT) compilation approach.
Hack is an open-source dialect of PHP created by Facebook, its most distinct feature is gradual typing (allowing both static and dynamic typing).
While there have been excellent guides around on how to install HHVM, most are for older releases of Ubuntu, and I ran into minor hiccups trying to follow them, therefor my aim is to streamline the process for the 18.04 release of Ubuntu.
Note that this tutorial assumes that your using the Apache Server to serve your website after it had been JIT compiled by HHVM.
Step 1 — Installing Prerequisites:
sudo apt-get updatesudo apt-get install -y curl software-properties-common apt-transport-https
Step 2 — Adding the HHVM PPA keys:
curl https://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -sudo apt-key finger 'email@example.com'
Step 3 — Adding the HHVM PPA and Installing:
sudo add-apt-repository https://dl.hhvm.com/ubuntusudo apt updatesudo apt install hhvm
Step 4 — Activating the HHVM FastCGI Protocol:
FastCGI is a popular protocol for communication between an application server (e.g. running your PHP code, in our case it’s HHVM) and a web-server (in our case it’s Apache).
The HHVM package comes equipped with an easy installer script for FastCGI integration, which can be called whenever a new server is installed on the machine.
This script will configure the FastCGI integration between any detected server and HHVM.
Step 5 — Fixing a Bug in the FastCGI Configuration file:
In our case, the chosen server is Apache, and its FastCGI configuration file has a bug, as in it doesn’t know where the default web directory is. To fix this, the following commands should be run:
sudo rm -rf /etc/apache2/mods-enabled/hhvm_proxy_fcgi.confsudo bash -c 'echo "ProxyPassMatch ^/(.+\.(hh|php)(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1" > /etc/apache2/mods-enabled/hhvm_proxy_fcgi.conf'sudo chmod 751 /etc/apache2/mods-enabled/hhvm_proxy_fcgi.conf
Step 6 — Restarting to Affect Changes:
We need to restart the Apache server, and HHVM.
sudo systemctl restart apache2
sudo systemctl restart hhvm
Step 1: — Testing the Default PHP Compiler/Interpreter:
It’s important to test if HHVM is detected as the default PHP compiler by the Apache server. To do this, we can write a simple info page in PHP and place it in the Apache web directory:
sudo bash -c 'echo "<?php phpinfo(); ?>" > /var/www/html/info.php'
Step 2: — Testing Compiler Functionality:
By writing a simple “Hello World” Program.
sudo bash -c 'echo "<html> <head> <title>PHP Test</title> </head> <body> <?php echo \"<p>Hello World</p>\"; ?> </body> </html>" > /var/www/html/hello.php'
If you want HHVM to start on boot, run the following command:
update-rc.d hhvm defaults
Installing HHVM is relatively easy, but it might require a few adjustments depending on the specific OS distro and its release, maybe in the future the process will get fully automated by Facebook, but for now this seems the best way to install it. Enjoy!
In case something goes wrong, you can send a message to my twitter handle, and I’ll try to fix it and update the article to reflect the changes.
- The Ubuntu word and associated logos are registered trademarks of Canonical Ltd.
- The HHVM logo is the creative property of Facebook Inc.
- I am not associated nor endorsed by: Canonical Ltd, Facebook Inc.
Hack's most basic feature is type annotations. Typing of objects have been around since PHP5, and PHP7 offers scalar…
We support x86_64 Linux, and offer prebuilt packages on variety of Ubuntu and Debian platforms.