HHVM


Read the history of HHVM development by Facebook.

This article is based on the HHVM documentation and practical experience.

Install HHVM

Based on the HHVM documentation.
All run as root (or prefix commands with sudo where appropriate)

apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0x5a16e7281be7a449
echo deb http://dl.hhvm.com/debian jessie main | tee /etc/apt/sources.list.d/hhvm.list
apt-get update
apt-get install hhvm

...
Setting up hhvm (3.14.5~jessie) ...
********************************************************************
* HHVM is installed.
*
* Running PHP web scripts with HHVM is done by having your
* webserver talk to HHVM over FastCGI. Install nginx or Apache,
* and then:
* $ sudo /usr/share/hhvm/install_fastcgi.sh
* $ sudo /etc/init.d/hhvm restart
* (if using nginx)  $ sudo /etc/init.d/nginx restart
* (if using apache) $ sudo /etc/init.d/apache restart
*
* Detailed FastCGI directions are online at:
* https://github.com/facebook/hhvm/wiki/FastCGI
*
* If you're using HHVM to run web scripts, you probably want it
* to start at boot:
* $ sudo update-rc.d hhvm defaults
*
* Running command-line scripts with HHVM requires no special setup:
* $ hhvm whatever.php
*
* You can use HHVM for /usr/bin/php even if you have php-cli
* installed:
* $ sudo /usr/bin/update-alternatives \
*    --install /usr/bin/php php /usr/bin/hhvm 60
********************************************************************
...

Configure Apache

Apache is needed to process requests, forward PHP or Hack pages to HHVM and send the results back to the client.

root@vps:~# /usr/share/hhvm/install_fastcgi.sh
[ ok ] Starting hhvm (via systemctl): hhvm.service.
Checking if Apache is installed
Detected Apache installation
Looking for custom proxy configuration
No custom proxy configuration found
Checking for enabled proxy_fcgi.load
Not found
Checking for enabled fastcgi.load
Not found
Checking for enabled fcgid.load
Not found
Checking for available proxy_fcgi.load
Found, checking for loading directives
Detected available proxy_fcgi.load configuration, setting up integration
Checking for available hhvm_proxy_fcgi.conf
Found, checking for loading directives
Detected available hhvm_proxy_fcgi.conf configuration, setting up integration
Checking for available proxy.load
Found, checking for loading directives
Detected available proxy.load configuration, setting up integration
Checking for available proxy.conf
Found, checking for loading directives
Detected available proxy.conf configuration, setting up integration
Enabling module proxy.load
Found available module
Module already enabled
Enabling module proxy.conf
Found available module
Module already enabled
Enabling module proxy_fcgi.load
Found available module
Creating a symlink
Finished creating a symlink
Force enabling module hhvm_proxy_fcgi.conf
Available module found
Removed possible duplicates
Enabling module hhvm_proxy_fcgi.conf
Found available module
Creating a symlink
Finished creating a symlink
Completed force enabling
Restarting apache
Finished restarting apache
Checking if Nginx is installed
Nginx not found

# Check status

root@vps:~# systemctl status hhvm
 hhvm.service - LSB: Starts The HHVM FastCGI Daemon
   Loaded: loaded (/etc/init.d/hhvm)
   Active: active (running) since Tue 2016-08-16 12:18:06 BST; 10min ago
   CGroup: /system.slice/hhvm.service
           6923 /usr/bin/hhvm --config /etc/hhvm/php.ini --config /etc/hhvm/server.ini --user www-data --mode daemon -vPidFile=/var/run...

root@vps:~# systemctl restart hhvm

root@vps:~# systemctl status hhvm
 hhvm.service - LSB: Starts The HHVM FastCGI Daemon
   Loaded: loaded (/etc/init.d/hhvm)
   Active: active (running) since Tue 2016-08-16 12:28:42 BST; 5s ago
  Process: 7260 ExecStop=/etc/init.d/hhvm stop (code=exited, status=0/SUCCESS)
  Process: 7267 ExecStart=/etc/init.d/hhvm start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/hhvm.service
           7276 /usr/bin/hhvm --config /etc/hhvm/php.ini --config /etc/hhvm/server.ini --user www-data --mode daemon -vPidFile=/var/run...

# Enable HHVM start on boot. Don't really need this as it is run by systemctl enable

root@vps:~# update-rc.d hhvm defaults

root@vps:~# systemctl enable hhvm
Synchronizing state for hhvm.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d hhvm defaults
Executing /usr/sbin/update-rc.d hhvm enable

# Logs are in /var/log/hhvm

root@vps:/var/log/hhvm# ls -l
total 0
-rw-r--r-- 1 www-data www-data 0 Aug 16 04:20 error.log

# Config is in /etc/hhvm
# server.ini = web server
# php.ini = command line

# Apache module confiiguration for FCGI is in /etc/apache2/mods-enabled
# hhvm_proxy_fcgi.conf
# proxy_fcgi.load

Troubleshooting

Sites return 404 errors.

Check the HHVM FCGI configuration file hhvm_proxy_fcgi.conf
The default entry is probably wrong for your server. Check the path and change if necessary.

# The default path (/var/www) below is probably wrong for your server - change it
ProxyPassMatch ^/(.+\.(hh|php)(/.*)?)$ fcgi://127.0.0.1:9000/var/www/$1

If your site uses pretty URL’s it is probably using Apache rewrite rules to achieve it.
For me, this broke sites served by HHVM.
The fix for that was to add hhvm.server.fix_path_info = true to /etc/hhvm/server.ini (see here) and restart HHVM and Apache.

Proxy configuration

The default proxy configuration in /etc/apache2/mods-enabled\hhvm_proxy_fcgi.conf works fine for a single site but it may not be appropriate for a server running virtual hosts.
To configure HHVM per vhost:

Comment on this article using form below. Requires email login only for authentication. HTML forbidden, Markdown only.