configure hhvm and apache for archlinux configure hhvm and apache for archlinux apache apache

configure hhvm and apache for archlinux


It can be done. Here is my Ubuntu web server example:

You need a way to hook HHVM into your Apache web server. This is done using FastCGI, which you need to install. Luckily, HHVM provides a shell script to set this up. Run the following...

sudo /usr/share/hhvm/install_fastcgi.sh 

Ensure HHVM fires up at boot, run this... (optional)

sudo update-rc.d hhvm defaults 

Configure HHVM and Apache Virtual Hosts

The install script will ask you to restart both HHVM and Apache. Don't just yet, otherwise your site visitors will be seeing some 404 action coming their way. Instead, open hhvmproxyfcgi.conf and comment the single ProxyPassMatch line that's in there.

sudo emacs /etc/apache2/mods-available/hhvm_proxy_fcgi.conf  # ProxyPassMatch ^/(.+\.(hh|php)(/.*)?)$ fcgi://127.0.0.1:9000/v

This stops all PHP/Hack scripts from being routed through FastCGI, this will allow you to choose which web applications you'd like to send through HHVM. If you're only running a single web application in your web server root, you don't need to do this, but I feel it's a smart move regardless.

Right now HHVM is running but has no way for scripts to be handed off to it. We need to add the ProxyPassMatch configuration to the Virtual Host Configuration for the web applications we'd like HHVM to power. Add this to each Virtual Host instance in each configuration file (both secure and non-secure traffic covered in the example below.).

sudo nano /etc/apache2/sites-available/hhvm.example.com.conf 

# HHVM Example - hhvm.example.com

<VirtualHost *:80>    ServerName hhvm.example.com    DirectoryIndex index.php    DocumentRoot /var/www/sites/hhvm.example    ProxyPassMatch ^/(.+\.(hh|php)(/.*)?)$ fcgi://127.0.0.1:9000/var/www/sites/hhvm.example/$1</VirtualHost>  <VirtualHost *:443>    ServerName hhvm.example.com    DirectoryIndex index.php    DocumentRoot /var/www/sites/hhvm.example    SSLEngine On    SSLCertificateFile   /etc/ssl/certs/hhvm.crt    SSLCertificateKeyFile    /etc/ssl/private/hhvm.key    SSLCACertificateFile  /etc/ssl/certs/hhvm.ca.crt    ProxyPassMatch ^/(.+\.(hh|php)(/.*)?)$ fcgi://127.0.0.1:9000/var/www/sites/hhvm.example/$1</VirtualHost>

You can also designate another port to explicitly use HHVM if you'd like to quickly A/B test the performance gains. To do this, simply open the port in /etc/apache2/ports.conf

Listen 8080 

Then in your Virtual Host configuration, create another instance with the new port specified and add the ProxyPassMatch configuration to the one you'd like to run HHVM on.

<VirtualHost *:80>    ... </VirtualHost>  <VirtualHost *:8080>    ...     ProxyPassMatch ^/(.+\.(hh|php)(/.*)?)$ fcgi://127.0.0.1:9000/var/www/$1</VirtualHost> 

Restart Apache and HHVM

Now, we are ready to kick Apache and HHVM in the head. Restart both services...

sudo service apache2 restart  sudo service hhvm restart