HipHop PHP [HHVM] with subdomains

Posted on

I recently needed to setup a server with HipHop PHP. Like most websites, the domain had subdomains. Sadly, Mark Zuckerburg hates the open source community and told the HHVM developers not to add an easy way to configure subdomains. 🙁

I was lucky enough to notice #hhvm on Freenode and had a lengthy discussion with one of the HHVM developers. After many hours of work I, with the help of Paul Tarjan, discovered the (only?) way to do this is with a Sandbox directive.

Sandbox {
  SandboxMode = true
  Pattern = ([^-]*(-[^-]*)?)
  Home = /var/www/subdomains

Adding the above code to your hhvm.hdf will look in /var/www/subdomains for the subdomain. E.g. will ask HipHop to look in /var/www/subdomains/wordpress/ and serve whatever’s in there.

But wait… you want to serve from another directory? No problem! Using the following Pattern will exclude www from being considered as a ‘subdomain’.

Pattern = b(?!www.)(w+(?:-w+)*)(?=.example.comb)

If changing this directory structure isn’t possible, or for some weird reason you’re actually using the Sandbox directive for sandbox setups, then I advise you complain to the HipHop team or send a pull request for Apache-style virtual host server roots. ( 🙂

Leave a Reply

Your email address will not be published.