The LAMP stack consists of Linux, Apache2, MySQL (MariaDB) and PHP. It’s the most popular opensource stack that powers more than half of all websites online today.

Servers that make up the stack are inter-changeable. For example, Apache2 can be replaced with Nginx and MySQL replaced with MariaDB. For a while now, PHP had always been the member of the stack that couldn’t be changed easily.

Now it’s possible to replace PHP with another compiler. So, for those want to achieve optimal speed, they run a custom stack which includes Linux, Nginx, MariaDB and HHVM. Configuring these will allow optimal performance for your websites, blog or applications.

This brief tutorial is going to show you how to install and configure HHVM on Ubuntu 15.04.

To get started, add HHVM repository and its key to your server and install it from there. First run the commands below to add HHVM repository key to your server

sudo wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -

Then run the commands below to add HHVM repository to your system

sudo echo deb http://dl.hhvm.com/ubuntu vivid main | sudo tee /etc/apt/sources.list.d/hhvm.list

Finally, run the commands below to update your system and install HHVM on Ubuntu 15.04.

sudo apt-get update && sudo apt-get install hhvm

After installing it, you’ll see a message that tells you HHVM is installed.

* HHVM is installed.
*
* Running PHP web scripts with HHVM is done by having your
* webserver talk to HHVM over FastCGI. Install nginx or Apache,
* and then:
* $ sudo /usr/share/hhvm/install_fastcgi.sh
* $ sudo /etc/init.d/hhvm restart
* (if using nginx) $ sudo /etc/init.d/nginx restart
* (if using apache) $ sudo /etc/init.d/apache restart
*
* Detailed FastCGI directions are online at:
* https://github.com/facebook/hhvm/wiki/FastCGI
*
* If you’re using HHVM to run web scripts, you probably want it
* to start at boot:
* $ sudo update-rc.d hhvm defaults
*
* Running command-line scripts with HHVM requires no special setup:
* $ hhvm whatever.php
*
* You can use HHVM for /usr/bin/php even if you have php-cli
* installed:
* $ sudo /usr/bin/update-alternatives \
* –install /usr/bin/php php /usr/bin/hhvm 60
********************************************************************

To allow Apache2 or Nginx web server to use HHVM, run the commands below.

sudo /usr/share/hhvm/install_fastcgi.sh

After running the above command, HHVM searches your systems for available web server. It first looks for Apache2 and if Apache2 isn’t found, then it looks for Nginx. So the best method is to install the web server first before installing HHVM.

So, install Nginx, then run the commands above to enable HHVM module for Nginx.

If you want HHVM to automatically startup everytime your server starts, run the commands below.

sudo update-rc.d hhvm defaults

If PHP-Cli is installed, it could conflict with HHVM. To resolve that, run the commands below.

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

Finally, run the commands below to start up HHVM

systemctl start hhvm

To test HHVM, create a test page in the root directory and type these lines in the file and save it.

sudo vi /var/www/html/hhvminfo.php

Type these lines in the file and save it.

<?php
phpinfo();
?>

Next, browse to the server /hhvminfo.php and you’ll see the test page below.

installing hhvm on ubuntu

 

Enjoy!

 

Frequently Asked Questions

How to add HHVM repository key to Ubuntu 15.04 server?

To add HHVM repository key, run the command: sudo wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -

What are the steps to add HHVM repository to Ubuntu 15.04 system?

To add HHVM repository, run: sudo echo deb http://dl.hhvm.com/ubuntu vivid main | sudo tee /etc/apt/sources.list.d/hhvm.list

How can I update my Ubuntu 15.04 system and install HHVM?

To update system and install HHVM, run: sudo apt-get update && sudo apt-get install hhvm

What are the components of a custom stack for optimal speed on Ubuntu 15.04 with HHVM?

A custom stack includes Linux, Nginx, MariaDB, and HHVM for optimal speed and performance on Ubuntu 15.04.

What is the command to install HHVM on Ubuntu 15.04?

To install HHVM on Ubuntu 15.04, run: sudo apt-get install hhvm

How can I run PHP web scripts with HHVM on Ubuntu 15.04?

To run PHP web scripts with HHVM, configure your webserver to talk to HHVM over FastCGI. Follow the detailed directions at: https://github.com/facebook/hhvm/wiki/FastCGI

What are the post-installation steps after installing HHVM on Ubuntu 15.04?

After installing HHVM, run the following commands: sudo /usr/share/hhvm/install_fastcgi.sh, sudo /etc/init.d/hhvm restart, and depending on your webserver, restart nginx or apache.

Where can I find detailed FastCGI directions for HHVM on Ubuntu 15.04?

For detailed FastCGI directions, refer to: https://github.com/facebook/hhvm/wiki/FastCGI