0

How to setup Nginx+HHVM on Debian Wheezy (HipHop Virtual Machine)

Now a days HHVM is very hot for PHP developers and sysadmins, HHVM is an open-source virtual machine designed for executing programs written in Hack and PHP. HHVM uses a just-in-time (JIT) compilation approach to achieve superior performance while maintaining the development flexibility that PHP provides.

So lets looks how to install and configure it with Nginx.

First you need to add HHVM repository


echo deb http://dl.hhvm.com/debian wheezy main | tee /etc/apt/sources.list.d/hhvm.list
wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | apt-key add -
apt-get update

Install Nginx and HHVM packages

apt-get install nginx-extras hhvm

Make HHVM service to start on boot

update-rc.d hhvm defaults

If you execute PHP scripts via php-cli then you need to replace the php cli binary

/usr/bin/update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60

Finally create a new virtualhost in nginx with very basic configuration.

server {
root /var/www/hhvm;
index index.php;

server_name hhvmtest.com;

location ~ \.(hh|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;
include fastcgi_params;
}
}

To test if ngix+hhvm is able to execute php create a a file index.php in your webroot (/var/www/hhvm) and put below code in it.

<?php echo phpinfo(); ?>

Retsart Nginx and HHVM services

/etc/init.d/hhvm restart
/etc/init.d/nginx restart

This should return “HipHop” only instead of standard phpinfo() output so don’t panic. You can also verify whether HHVM is in action in place of default PHP-CLI binary by executing below command.

/usr/bin/php -v

This should return HHVM details instead of standard php -v output.

Now your basic Nginx+HHVM webstack is ready and you can test real app on it (WordPress my favorite) and customized it as per your requirements.