HipHop Virtual Machine (HHVM) is a process virtual machine developed by Facebook, serves as an execution engine for PHP, based on JIT. HipHop Virtual Machine (HHVM) is an Open Source Software like PHP. We can install HipHop Virtual Machine (HHVM) on the top of Nginx Web Server Software, that is the basic importance to know about HipHop Virtual Machine. HipHop for PHP (HPHPc) was also developed by Facebook, a PHP transpolar and HipHop Virtual Machine (HHVM) is the succeeder.
HipHop Virtual Machine (HHVM) : Basics
We usually use PHP5-FPM with Nginx Web Server Software. Instead of only running PHP5-FPM, basically we can use HipHop Virtual Machine (HHVM) on FastCGI
-based web server, on a developmental setup first and later adjust setting to deploy on production server. FastCGI
support for HHVM was not available before December 2013. PHP5-FPM is a FastCGI Process Manager. So, practically we can compare the performance of PHP5-FPM
versus HHVM. If we want to run WordPress, normally, HHVM with PHP-FPM fallback is used. HHVM might not support all the WordPress themes and plugins.
A process virtual machine or application virtual machine or Managed Runtime Environment (MRE), runs like a normal application inside a Linux based host OS and supports a single process. Exit means destruction of the virtual machine. The basic purpose of process virtual machine is to provide a programming environment that provides an abstraction layer away from the underlying hardware or Host OS. It allows a program to get executed. Process virtual machines usually provide a high-level abstraction for high-level programming language. In practice, the process virtual machines are implemented using an interpreter and just-in-time compilation. They have a dedicated website :
---
http://hhvm.com
Hacks will be available on the official website, as well as more information. Just to tell you – the just-in-time compilation can be used on Nginx on other ways. Facebook possibly developed HHVM as Zend and Apache2 web server combination is probably not great to resource hungry applications written in PHP. PHP is bad, well accepted; but we need to use PHP as there are lesser projects written in Python, Ruby, Perl.
Knowing theory on HipHop Virtual Machine (HHVM) is great, but whether HipHop Virtual Machine will work properly on production server for WordPress, we can not give warranty. Facebook developed for their own purpose. You can test.
Using HipHop Virtual Machine (HHVM) with Nginx on Ubuntu
You need to have pcre-jit
on Nginx. If Nginx was installed before, you should check the compilation by running nginx -V
command. Possibly the latest aptitude version of Nginx has no bug with pcre-jit
. In other words – probably building Nginx from source will be better, although apt-get install nginx
should make pcre-jit
to work or run fine. If apt-get install nginx
does not work, you have to stop nginx and recompile from source or fully uninstall nginx, clear cache and freshly build.
So much words has been used or abused as you might want just to test HHVM on an existing setup.
First, for Nginx, we need to install the dependencies :
1 | apt-get update && apt-get install libpcre3-dev build-essential libssl-dev dpkg-dev build-essential zlib |
wget nginx, unzip it and cd to the directory and compile in this way :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ./configure \ --with-http_ssl_module \ --with-pcre-jit \ --with-ipv6 \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_geoip_module \ --with-http_gzip_static_module \ --with-http_spdy_module \ --with-http_sub_module \ --with-http_xslt_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio CFLAGS="-O3" CXXFLAGS="-O3" make |
make install
is the next command and you have to copy to the right directory. We deliberately kept the Nginx part short yet at least understandable.
This is the official way to install HHVM :
1 2 3 4 5 6 7 8 9 | wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add - # next command echo deb http://dl.hhvm.com/ubuntu trusty main | sudo tee /etc/apt/sources.list.d/hhvm.list # next command apt-get update && apt-get install hhvm # optional to solve bugs apt-get install libgmp-dev && apt-get install libmemcached-dev # help command hhvm --help |
There are at least two use HHVM. One is using supervisord
and another is the regular way. We are taking the regular way. If it is an empty server, delete any existing html file from the public root directory and create a php file :
1 2 3 4 5 6 7 8 9 10 11 | nano index.php # copy and paste <?php echo '<h1>HipHop Virtual Machine (HHVM) Works!</h1>'; # ^ + O # ^ + X # nano is the text editor # start server hhvm -m server # execute this script /usr/share/hhvm/install_fastcgi.sh |
Test by visiting the webpage on browser. If PHP5-FPM was used, you need to comment out these from your default nginx ghost config file, default is /etc/nginx/sites-available/default
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | nano /etc/nginx/sites-available/default # Edit it by finding with ^ + W # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # fastcgi_split_path_info ^(.+\.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: # fastcgi_pass unix:/var/run/php5-fpm.sock; # fastcgi_index index.php; # include fastcgi_params; #} # Edit ends # ^ + O # ^ + X # add HHVM at boot, do not do before you know # what you are doing update-rc.d hhvm defaults # restart nginx nginx -v # assuming no bad output service nginx restart # you should add runtimes by manually checking ! https://github.com/facebook/hhvm/tree/master/hphp/runtime/ext |
This is not fallback to PHP5-FPM setup. If you wanted fallback, instead of editing the file above, we would approach in this way :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | nano /etc/hhvm/server.ini # change server port from 9000 to 8000 # ^ + W hhvm.server.port = 8000 # Edit ends # ^ + O # ^ + X nano /etc/hhvm/php.ini # add these at the end, no ; at the end of each hhvm.log.header = true hhvm.log.natives_stack_trace = true # Edit ends # ^ + O # ^ + X nano /etc/nginx/hhvm.conf # this should be the value fastcgi_pass 127.0.0.1:8000; # Edit ends # ^ + O # ^ + X nano /etc/nginx/conf.d/fastcgi.conf # add this at the end fastcgi_keep_conn on; # Edit ends # ^ + O # ^ + X nano /etc/nginx/conf.d/upstream.conf # edit or modify properly upstream php { server 127.0.0.1:8000; server 127.0.0.1:9000 backup; } upstream debug { # pool server 127.0.0.1:9001; } # Edit ends # ^ + O # ^ + X ## restart all the services service hhvm restart php5-fpm -t # hope right output service php5-fpm restart nginx -t # hope right output service nginx restart |
There is no issue with KVM or Xen virtualization, but with OpenVZ there can be issue with HipHop Virtual Machine (HHVM). The above stuff is for Rackspace Cloud Server. This might not work on Amazon or DigitalOcean (we have not tested).
Tagged With Hip Hop Virtual Machine