Speed up PHP application using HHVM + Nginx

We are going to speed up our existing php application by using HHVM. HHVM is a virtual machine designed for executing the program by using Just-in-time(JIT) compilation approach. It is a new techology which is used by Facebook.Also it help us to achieve the superior performance. It is an Open Source at Facebook. Also HHVM has realized over a 9x increase in web request throughput and over a 5x reduction in memory consumption for Facebook compared with the PHP 5.2 engine + APC

Most of the PHP frameworks, packages are supported by HHVM. See the compatability details on this page: http://hhvm.com/frameworks/

This tutorial we are configure PHP with HHVM + nginx. We are going to use Ubuntu 14.04 LTS 64bit.

First we start with nginx installation. Just run the following simple command in the terminal

Next, We go to install HHVM. For installation i would recommend pre build packages because it makes installation easy.Just follow the commands.

If you’re using HHVM to run web scripts, you probably want it to start at boot:

That’s it. We have done HHVM installation. Now, We are going to configure with nginx by using to run following command in terminal

By running this command it creates hhvm.conf file inside the /etc/nginx/ directory and also it adds include hhvm.conf line in every server block of your default file in /etc/nginx/sites-available/ .Now if there is no default file in /etc/nginx/sites-available/ then the inlcude lines are not added in server blocks.You will have to add them manually.You should check the files inside /etc/nginx/sites-available/ and add below lines any where inside Server block.


Make sure hhvm.conf(/etc/nginx/hhvm.conf) should has following lines

This configuration we are using fast-cgi socket instead of port because of memory leak problem (http://yuhans.blogspot.in/2014/07/dealing-with-hhvm-memory-leak.html).

HHVM has two configuration file which is located in /etc/hhvm/.

  1. server.ini – HHVM related configuration settings
  2. php.ini – PHP configuration settings

/etc/hhvm/server.ini :

/etc/hhvm/php.ini :

For more details about configuration setting refer this url : https://github.com/facebook/hhvm/wiki/INI-Settings

Finally, We restart the nginx and hhvm by using following command

You can also test if Nginx is using HHVM or not.To test just create a file hhvm.php in /usr/share/nginx/html .After creating that write below code in it

Now open the file in browser (your-domain-name.com/hhvm.php).You can see the output Hip Hop Virtual Machine is working.If the output is Hip Hop Virtual Machine is not working then you check the errors in HHVM log files or Nginx log files.Nginx log files are located in /var/log/nginx directory.

HHVM Performance status

I hope this will help to my blog readers. You can try it with existing or new development application. Thank you.

  • http://www.lives.nl Menno Bouma

    Hi Azhagu,

    Thanks for this great post! I’m running several WordPress websites with HHVM. Sometimes plugins give errors like hphp_invoke. Is it possible to exclude plugins from HHVM? It looks like urls starting with /wp-admin/admin-ajax.php are not working…

    – Menno

    • Azhagu Pandian

      I don’t think whether we can exclude plugin from HHVM