Question: I'm try to host several domain on the same VPS, using HHVM to serve the pages.

I'm wondering how can I write the VirtualHost in order to point the right folder in my /var/www directory ?

For example xxx.domain.com >> /var/www/domain.com/

Answer: 
Good news. Since the release of HHVM 2.3 (Dec 13, 2013), you can run HHVM in FCGI mode. Use either Nginx or Apache and it works wonderfully.

Reference: <http://www.hhvm.com/blog/1817/fastercgi-with-hhvm>

With an older version of HHVM you can run multiple server instances on internal ports, i.e. 8001, 8002, etc. Then configure Nginx as a reverse proxy. (Apache can do that too).

```
upstream node1{
    server 127.0.0.1:8001;
}

upstream node2{
    server 127.0.0.1:8002;
}
server {
    ...
    server_name server1.com;
        location ~ \.php$ {
        proxy_pass http://node1;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_redirect off;
            proxy_buffering off;
            proxy_set_header        Host            $host;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Ssl on; #only for https
    }
}

server {
    ...
    server_name server2.com;
        location ~ \.php$ {
        proxy_pass http://node2;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_redirect off;
            proxy_buffering off;
            proxy_set_header        Host            $host;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Ssl on; #only for https
    }
}

```

Of course this setup takes up a lot of memory. Go with 2.3 if you can upgrade.
On Nginx, the only way I was able to get this to work was to use `/` as `SourceRoot` for HHVM, and to add a `/` in `fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;` in my `/etc/nginx/hhvm.conf` file. With that combination, I'm running ~7 sites without a problem so far. I'm running Ubuntu 13.10 64-bit. 

In `/etc/hhvm/server.hdf`, change `SourceRoot = /var/www` to `SourceRoot = /`:

```
Server {
  Port = 9000
  SourceRoot = /
  DefaultDocument = index.php
}

```

In `/etc/nginx/hhvm.conf`, add a / in front of `$document_root$fastcgi_script_name;`:

```
location ~ \.php$ {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    fastcgi_keep_conn on;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME /$document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    fastcgi_read_timeout 300;
    include        fastcgi_params;
}

```

You may also need to change `fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;` to `fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;`, at least I had to with mine. 

There may be security implications by using `/` as your SourceRoot - I mitigate this as much as I can by firewalling port 9000 so only localhost can reach it. Or you can use a socket instead. Not fool-proof, but from what I've seen so far it's OK.