4

First, i installed apache24 from AUR and hhvm from AUR (HipHop VM 2.4.0 (rel)). apache24 has mod_proxy_fcgi enabled. Running the php file from terminal with hhvm seems to work fine, but i cannot configure it to work with apache.
in httpd.conf i have:

ProxyPass / fcgi://127.0.0.1:9000/srv/http/

, then i run the hhvm server from doc_root with:

sudo hhvm --mode server -vServer.Type=fastcgi -vServer.Port=9000

, but when access the http link from browser i get:

"HipHop Notice: File could not be loaded: proxy:fcgi://127.0.0.1:9000/srv/http/index.php"

any suggestions?

ljupcho
  • 41
  • 3

1 Answers1

1

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 
unixmiah
  • 3,081
  • 1
  • 12
  • 26