mdxogq
Last Updated: February 25, 2016
·
2.923K
· nmalcolm

HipHop PHP [HHVM] with subdomains

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 = ([^-]*(-[^-]*)?)\.example\.com
  Home = /var/www/subdomains
}

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

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

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

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. (https://github.com/facebook/hiphop-php/issues/885) :)

https://github.com/facebook/hiphop-php

3 Responses
Add your response

8166

I've updated the Pattern for checking for a www subdomain. The previous one... didn't exactly work.

over 1 year ago ·
11681

"Sadly, Mark Zuckerburg hates the open source community"

This is complete bullshit and you know it.

over 1 year ago ·
11682

@jtreminio I'm sure you can gather from the rest of that sentence, and the marvelous contributions Facebook has made to the open source community, that it was purely a joke.

over 1 year ago ·