Install HHVM and NGINX on debian

February 23, 2015

Facebook recently released hhvm with fast-cgi support. This post will show you how you can set this up yourself.

Install hhvm

$ echo deb http://dl.hhvm.com/debian wheezy main | tee /etc/apt/sources.list.d/hhvm.list
$ apt-get update
$ apt-get install hhvm-fastcgi

Start hhvm-fastcgi at boot

$ update-rc.d hhvm-fastcgi defaults

Install nginx

$ echo deb http://nginx.org/packages/debian/ wheezy nginx | tee /etc/apt/sources.list.d/nginx.list
$ wget http://nginx.org/keys/nginx_signing.key
$ apt-key add nginx_signing.key && rm nginx_signing.key
$ apt-get update
$ apt-get install nginx

Configure nginx

upstream hhvm {
  server 127.0.0.1:9000;
}

server {
    listen 80;

    server_name _;
    root /var/www/;

    error_log /var/log/nginx/site.error.log;
    access_log /var/log/nginx/site.access.log;

    rewrite ^/index\.php/?(.*)$ /$1 permanent;

    location / {
        index index.php app.php;
        try_files $uri @rewriteapp;
    }

    location @rewriteapp {
        rewrite ^(.*)$ /index.php/$1 last;
    }

    # pass the PHP scripts to FastCGI server from upstream phpfcgi
    location ~ \.php(/|$) {
        fastcgi_pass hhvm;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param  HTTPS off;
    }
}

comments powered by Disqus