+0 votes
in Webmasters by (1.5m points)

How to install HHVM on Ubuntu with Apache

1 Answer

+1 votes
by (725k points)
 
Best answer

For some time now I wanted to tell you about Hip Hop Virtual Machine best known for its abbreviation HHVM . It is not a music group but a virtual machine designed by Facebook for their own use but they have released the code so we can all use it.

image

HHVM supports PHP and Hack , the latter being a new PHP-based programming language that gives us new features such as the use of collections (alternatives to PHP arrays), static typing, allows the use of Lambda expressions, etc. … How it is not the objective of the article to speak in depth about the Hack language you can visit the official page with all the information (in English).

The main feature of HHVM is that it has a JIT (just-in-time) compiler. To explain it simply, HHVM compiles PHP (or Hack language) in bytecode and then this bytecode is translated into machine language using the JIT compiler. The compilation process described allows various optimizations to be performed and thus increase the performance of our PHP applications. If you want to know more about HHVM, it is best to visit its official website and its GitHub page.

Before continuing I should also clarify that the configuration I show in this tutorial on how to install HHVM in Ubuntu, is not intended for servers in production .

HHVM installation guide on Ubuntu 14.04 x64 with Apache

The first thing will be to describe the work environment we are working on so you can replicate it. The tests have been performed on a DigitalOcean VPS with 512MB of RAM and with the Ubuntu 14.04 x64 operating system. I must clarify that HHVM only works on x64 operating systems , so do not use a 32-bit operating system because it will not work.

The version of Apache installed at the time of writing the tutorial is Apache 2.4.7, which we installed apt-get by default (later I describe how to do it) .

Installing Hip Hop Virtual Machine from scratch.

Once we access our server through SSH with PuTTY for example, we have to execute the commands described in the official documentation , which are the following for Ubuntu 14.04:

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

At this point HHVM is already installed and we must install Apache, for this we execute the following command:
sudo apt-get install apache2

When the installation process is finished we must configure Apache and HHVM to work together, to achieve this we execute the commands:

sudo /usr/share/hhvm/install_fastcgi.sh
sudo /etc/init.d/hhvm restart
sudo service apache2 restart

At this point we will do two tests to verify that everything has gone well. First we execute the php -v command and something similar to:

Compiler: tags/HHVM-3.4.0-0-g817b3a07fc4e509ce15635dbc87778e5b3496663
Repo schema: 0e12aaa31fae66b5591f65603de50c9d62caafac
Extension API: 20140829

The second will be to access our Apache server to verify that it is working. For this we must put the IP in our browser as follows: http://ip_servidor , for example, http://128.179.37.10

During the previous HHVM configuration a file is created that causes a 404 error when we try to access php files. The solution is to delete this configuration file with the following command:

sudo rm -rf /etc/apache2/mods-enabled/hhvm_proxy_fcgi.conf

Now we edit the Apache configuration file with the command:
nano /etc/apache2/apache2.conf

We move to the directory configuration section and enter the line:
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1

image

It has to be as seen in the image (for more advanced configurations consult the official documentation ).

Restart Apache and with this all files with PHP extension will pass through HHVM.
sudo service apache2 restart

To prove that it really works, we create a test php file and then access it:

cd /var/www/html
nano test.php

We add the line:

<?php phpinfo(); ?>

We access the php file through the browser:

image

I hope the tutorial has been helpful and if you have any questions, do not hesitate to use the comments.


Most popular questions within the last 20 days

...