Skip to main content

First steps with hhvm

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· 3 min read
Stephan Hochdörfer
Head of IT Business Operations

UPDATE (04/2014): Since Facebook decided to remove the webserver functionality from the "official" binaries this howto will not work anymore! Read here how to set things up with the current version of hhvm.

After reading all the buzz about hhvm I thought I should give it a try to see what it is all about. Following my current no-local-installs policy I used the following vagrant configuration to set up a new virtual machine for hhvm.

Vagrant.configure("2") do |config|
config.vm.define "box" do |box_cfg|
box_cfg.vm.box = 'debian-wheezy'
box_cfg.vm.box_url = 'https://dl.dropboxusercontent.com/u/86066173/debian-wheezy.box'
box_cfg.vm.hostname = "hhvm"

# Forward a port from the guest to the host
box_cfg.vm.network :forwarded_port, guest: 80, host: 8080

# share folder to the guest VM
box_cfg.vm.synced_folder ".", "/vagrant", owner: "www-data", group: "vagrant"
end
end

Installing hhvm on a Debian Wheezy box is pretty straight forward. It boils down to the following commands which you need to execute as root user:

wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | apt-key add -
echo deb http://dl.hhvm.com/debian wheezy main | tee /etc/apt/sources.list.d/hhvm.list
apt-get update
apt-get install hhvm

Since I already had the PHP CLI package installed I needed to point the /usr/bin/php symlink to the hhvm binary. Instead of changing the symlink manually I used Debians update-alternatives command:

update-alternatives --install /usr/bin/php php /usr/bin/hhvm 1

To configure the hhvm server I needed a config.hdf file that looks like this. If you want to use a different port number you need to change the setting in the Vagantfile above as well:

Server {
Port = 80
SourceRoot = /vagrant/webroot/
DefaultDocument = index.php
}

Eval {
Jit = true
}

Log {
Level = Error
UseLogFile = true
File = /var/log/hhvm/error.log
Access {
* {
File = /var/log/hhvm/access.log
Format = %h %l %u %t \"%r\" %>s %b
}
}
}

VirtualHost {
* {
Pattern = .*
RewriteRules {
dirindex {
pattern = ^/(.*)/$
to = $1/index.php
qsa = true
}
}
}
}

StaticFile {
FilesMatch {
* {
pattern = .*\.(dll|exe)
headers {
* = Content-Disposition: attachment
}
}
}
Extensions {
css = text/css
gif = image/gif
html = text/html
jpe = image/jpeg
jpeg = image/jpeg
jpg = image/jpeg
png = image/png
tif = image/tiff
tiff = image/tiff
txt = text/plain
}
}

Starting the server was just a matter of the following command:

hhvm -m server -c config.hdf

Last but not least I had to create a simple PHP file in /vagrant/webroot/index.php. By pointing my browser to http://localhost:8080 I was able to view my first PHP script running on hhvm. Whilst web request work fine I am still struggling with getting PHPUnit to execute my test cases. When running PHPUnit on the command line it seems that it is not able to find unit tests. Seems I need to investigate in that issue.