This guide will show you how to install HHVM (HipHop Virtual Machine) on an Ubuntu 20.04 server using Apache or Nginx. HHVM is a process virtual machine designed to execute Hack and PHP programs. HHVM runs programs at run time rather than prior, which gives HHVM high-caliber performance over a typical PHP install. HHVM was open-sourced and developed by Facebook.

In this post, we will show you how to install HHVM with Nginx on Ubuntu 20.04.

Prerequisites

  • A server with Ubuntu 20.04 installed. HHVM requires the 64-bit version.  If you do not have a server, try a market-leading Virtual Private Server in under 30 seconds from Atlantic.Net
  • Nginx installed on your server. You can follow our guides on installing Nginx if needed.

Step 1 – Install HHVM

By default, HHVM is not included in the Ubuntu 20.04 default repository. So you will need to add the HHVM repository to the APT.

First, install the required dependencies with the following command:

apt-get install software-properties-common apt-transport-https

Once all the dependencies are installed, add the GPG key using the following command:

apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xB4112585D386EB94

Next, add the HHVM repository to the APT with the following command:

add-apt-repository https://dl.hhvm.com/ubuntu

Once the repository is added, install the HHVM with the following command:

apt-get install hhvm -y

Once installed, verify the installed version of HHVM using the following command:

hhvm --version

You should get the following output:

HipHop VM 4.110.0 (rel)
Compiler: 1621283449_427599063
Repo schema: d1ae8e21bf3419a65f12a010527485564e719d07

At this point, HHVM is installed in your server.

Step 2 – Configure HHVM

By default, HHVM is configured to listen on the IPv6 address only. So you will need to configure it to listen on the localhost. You can do it by editing the server.ini file:

nano /etc/hhvm/server.ini

Add the “hhvm.server.ip = 127.0.0.1” line as shown below:

pid = /var/run/hhvm/pid

; hhvm specific

hhvm.server.port = 9000
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.log.use_log_file = true
hhvm.log.file = /var/log/hhvm/error.log
hhvm.repo.central.path = /var/cache/hhvm/hhvm.hhbc
hhvm.server.source_root = /var/www/html/
hhvm.server.ip = 127.0.0.1

Save and close the file then start the HHVM service with the following command:

systemctl start hhvm

Now, check the HHVM listening port with the following command:

ss -antpl | grep 9000

You should get the following output:

LISTEN    0         128              127.0.0.1:9000             0.0.0.0:*        users:(("hhvm",pid=6064,fd=23))   

Step 3 – Start HHVM Server

Next, create a sample PHP file to the Nginx web root directory:

nano /var/www/html/info.php

Add the following lines:

#!/usr/bin/env hhvm
<?hh
namespace Hack\UserDocumentation\Fundamentals\ProgramStructure\Examples\LegacyHelloWorld;

<<__EntryPoint>>
function main(): void {
  print("Hello, World!\n");
  exit(0);
}

Save and close the file then change the directory to the Nginx root directory and start the HHVM server on port 8080:

cd /var/www/html/
hhvm -m server -p 8080 -vServer.AllowRunAsRoot=1

Now, open your web browser and access your info.php file using the URL http://your-server-ip:8080/info.php. You should see the following page:

HHVM Page
Now, press CTRL+C to stop the server.

Step 4 – Configure HHVM to Run with Nginx and FastCGI

HHVM comes with a script to install FastCGI based on the web server you have installed.

You can run this script using the following command:

/opt/hhvm/4.110.0/share/hhvm/install_fastcgi.sh

This script will create a new hhvm.conf configuration file inside the Nginx conf directory:

cat /etc/nginx/hhvm.conf

You should see the following output:

location ~ \.(hh|php|hack)$ {
    fastcgi_keep_conn on;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

Now, restart the Nginx service to apply the changes:

systemctl restart nginx

Now, you can access your PHP file using the URL http://your-server-ip/info.php.

Conclusion

Congratulations on installing HHVM on Ubuntu 20.04. Try it out with some of your favorite CMS’s like WordPress or Drupal and you should see a performance increase especially under load. Thank you for following along this how to, please check back for more updates.