Hello! In this article we are going to setup an open source virtual machine that is designed for executing the programs written in Hack and PHP with NGINX web server where as Hack is a programming language for the Hiphop Virtual Machine created by facebook as a dialect of PHP. So this tutorial is going to be interested once get used of it and will be able to speed up your PHP applications. HHVM uses a just-in-time (JIT) compilation approach to achieve superior performance while maintaining the development flexibility that PHP provides. Let’s follow the below steps to install and configure HHVM in your environment.
HHVM setup only supports 64-Bit Operating system, so make sure that you have installed your operating system that supports 64-Bit architecture. Then you must have super user privileges to perform the required tasks.
You can check your system architecture and other host information with below command.
[email protected]:~# hostnamectl
Its always been been a good practice that your system should be proper updated before you setup any application. To update your operating system you can simply run the below command.
[email protected]:~# apt-get update
As we will be doing the HHVM setup using NGINX web server, so its must be installed prior to the installation of HHVM. You are to use use any other web server like Apache as per your organizational requirements.
Let’s run the following command to install Nginx web server on ubuntu 15.04.
[email protected]:~# apt-get install nginx
During the installation process you will be asked to continue with the installation operation, so press “Y” to continue as shown below to get your Nginx web server installed.
Now check the services of Nginx web server, it should be running and enabled as default. You can check and start its services as below.
The Nginx status show the active status of running services.
Now let’s proceed with installation of Hip Hop Virtual Machine on Ubuntu 15.04. As its package is not available in Ubuntu’s built in repository that why we have to add the HHVM repository to our Ubuntu repository file “/etc/apt/sources.list” and then update the repository by using the following commands in the terminal.
[email protected]:~# wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add –
[email protected]:~# echo deb http://dl.hhvm.com/ubuntu vivid main | sudo tee /etc/apt/sources.list.d/hhvm.list
To update the newly added repositories once again run the update command so that the installation package of HHVM will be available through its Ubuntu Repository list.
[email protected]:~# apt-get update
Once your system is up-to-date, run the following command to start the installation of HHVM package.
[email protected]:~# apt-get install -y hhvm
The installation will be done with addition of some extra packages as shown.
At the end of installation process of HHVM you will see its installation complete message with addition to some instructions to getting started with HHVM usage.
HHVM Configuration with Nginx
When the installation is finished, now we need to configure the Nginx web server to use HHVM as per instructed above. So, let’s issue the below command as shown.
[email protected]:~# /usr/share/hhvm/install_fastcgi.sh
It will check for the installed web server, enable its module and then restart its services.
To use HHVM for “/usr/bin/php” even if you have “php-cli” installed, run the below command.
[email protected]:~# /usr/bin/update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60
Now start HHVM service and check its status if everything is fine.
[email protected]:~# service hhvm status
In order to test HHVM for the confirmation if everything is installed and configured properly we will create a php file in the document root directory of your web server, restart Nginx services and then access it from the browser.
[email protected]:~# vim /var/www/html/info.php
[email protected]:~#service nginx restart
Now open your web browser and access the “info.php” file after saving the changes with and restart of Nginx services.
You have HHVM running on your Ubuntu 15.04 node which is much capable to serve PHP scripts more faster and efficient with Nginx on the top of your websites. Its gives you the big advantage of its fast speed than really all of Magento is faster, including payment and backend also by using HHVM to execute PHP, a lot less CPU power is used.