How to Install, Configure & Run HHVM in Amazon Linux server with Apache?

September 15th, 2022

How to install , configure and run HHVM in Amazon Linux server with Apache

HHVM is an open-source virtual machine designed for executing programs written in Hack and PHP. HHVM uses a just-in-time (JIT) compilation approach to achieve superior performance while maintaining the development flexibility that PHP provides.

We will get a lot of information about what is HHVM from the web. The most difficult part of it is to get a  step by step process of how to install HHVM. For supported platforms, HHVM official website itself provides some installation steps but for unsupported HHVM platforms installation of  packages and compilation steps are less available.

Here we are providing step by step process to install, configure and run HHVM in an unsupported platform Amazone Linux server with Apache

1:  Install Apache and httpd-devel

         1: Install Apache (how to install Apache is not included in this doc. Please refer appropriate docs for that )

         2: Check whether you have the required build files for handling the HHVM. Check whether you have a build directory in Apache and that directory has some required files like system.mk

                    a:  Find  your installed Apache root :

apachectl -V

The above comment will output as follows

Server version: Apache/2.2.31 (Unix)

Server built:   Aug 13 2015 23:45:37

Server's Module Magic Number: 20051115:40

Server loaded:  APR 1.5.0, APR-Util 1.4.1

Compiled using: APR 1.5.0, APR-Util 1.4.1

Architecture:   64-bit

Server MPM:     Prefork

threaded:     no

    forked:     yes (variable process count)

Server compiled with....

-D APACHE_MPM_DIR="server/mpm/prefork"

-D APR_HAS_SENDFILE

-D APR_HAS_MMAP

-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)

-D APR_USE_SYSVSEM_SERIALIZE

-D APR_USE_PTHREAD_SERIALIZE

-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT

-D APR_HAS_OTHER_CHILD

-D AP_HAVE_RELIABLE_PIPED_LOGS

-D DYNAMIC_MODULE_LIMIT=128

-D HTTPD_ROOT="/etc/httpd"

-D SUEXEC_BIN="/usr/sbin/suexec"

-D DEFAULT_PIDLOG="run/httpd.pid"

-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"

-D DEFAULT_LOCKFILE="logs/accept.lock"

-D DEFAULT_ERRORLOG="logs/error_log"

-D AP_TYPES_CONFIG_FILE="conf/mime.types"

-D SERVER_CONFIG_FILE="conf/httpd.conf"

Here, check the  HTTPD_ROOT  , if it says  etc/httpd , check whether you have a build directory inside this etc/httpd .  Some times this  HTTPD_ROOT is /etc/apache2 , depends on the server we have installed. If etc/httpd then for all later installations we are going to use the httpd folder . If it is  etc/apache2 , then, for all the installations that comes later, we will use the apache2 folder.

Check for build directory . Here in this document , we are using the httpd based on the above output . If you have got apache2 , then use apache2 instead of httpd.

Find all the httpd folder

whereis httpd

You may get the an output similar to

httpd: /usr/sbin/httpd.worker

/usr/sbin/httpd.event

/usr/sbin/httpd

/usr/lib64/httpd

/etc/httpd /usr/include/httpd                   

/usr/share/man/man8/httpd.8.gz

These are the httpd folders . Use cd comments to walk through this folders and check if we have build directory. One example I can give as follows

cd /usr/lib64/httpd

use ls comment to see the files/folders in this .

ls

Similarly, use ls with respect to the httpd folders to find the build folder.If you didn’t find a build folder , we need to install that . For that use

sudo yum install -y httpd-devel

After that check, we have updated the httpd and we got the build directory. Recheck using  whereis httpd and cd to each httpd and ls on it. I got the build directory in cd /usr/lib64/httpd . Also confirm that you have the following files inside that build directory. Use ls comment to see the files inside build directory.

config_vars.mk  library.mk  mkdir.sh    rules.mk

instdso.sh      ltlib.mk    program.mk  special.mk

2:  Install mod_proxy_fcgi

Apache 2.4 shipped mod_proxy_fcgi as part of the core distribution. This git repository provides a modified version backported to work with Apache 2.2 in order to work on older distributions (eg. Red Hat Enterprise Linux 6).

To get the source, compile, and install: Do the following one by one

 sudo git clone https://github.com/ceph/mod-proxy-fcgi

 cd mod-proxy-fcgi

 sudo autoconf

 sudo ./configure

 sudo make

 sudo make install

After this make sure that mod_proxy_fcgi is installed . To do that , check for a modules folder inside the httpd folder. Search similar to what we have done for finding the build folder earlier . I found my modules folder of httpd inside /etc/httpd

cd /etc/httpd

ls

If the installation goes ok , you can see mod_proxy_fcgi.so inside that folder

Now we need to load this module inside our httpd config file. This is the main configuration file of Apache . Locate your httpd config file. I found my httpd.conf file inside  /etc/httpd/conf/httpd.conf . Open that file

sudo vim  /etc/httpd/conf/httpd.conf

Go through that file and find the place where a list of LoadMoudules are written.

Check for the line , LoadModule proxy_module modules/mod_proxy.so . If you dont find such one , please add the same . Then add our new installed mod_proxy_fastcgi as follows.

 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

save that file (press escape , then :wq will save the file ).

Now restart your Apache as follows .

sudo service httpd restart

You will get the output as

[[email protected] /]$ sudo service httpd restart

Stopping httpd:                                          [  OK  ]

Starting httpd:                                            [  OK  ]

3:  Install mod_fastcgi

Download the module and install . Lets download to /usr/local/src.

Before downloading , remember where your httpd/apache2 build directory is

in my case , /usr/lib64/httpd

Do the following steps one by one:

cd /usr/local/src

sudo  wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz

sudo tar -xzvf mod_fastcgi-current.tar.gz

sudo cp Makefile.AP2 Makefile

sudo make top_dir=/usr/lib64/httpd

sudo make top_dir=/usr/lib64/httpd install

keep in mind that top_dir = the build directory

If the installation goes fine, you can see mod_fastcgi. Inside the modules folder of httpd . Check similar to what we have done for mod_proxy_fcgi.so.

Then load this new installed  mod_fastcgi inside the httpd conf file . Add the following to that file just below the previous LoadModule that we have added for mod_proxy_fastcgi

LoadModule fastcgi_module modules/mod_fastcgi.so

Now restart your Apache as follows .

sudo service httpd restart

You will get the output as

[[email protected] /]$ sudo service httpd restart

Stopping httpd:                                           [  OK  ]

Starting httpd:                                            [  OK  ]

4:  Install HHVM Dependencies

First update all package and install all the dependencies. Do the following one at a time. A step by step approach is better because its easy to trace any error that you may come across during installation. Some of the installations may be already installed.

sudo yum -y update

sudo yum -y install    autoconf

sudo yum -y install    automake

sudo yum -y install    binutils-devel

sudo yum -y install    boost-devel

sudo yum -y install    bzip2-devel

sudo yum -y install    chrpath

sudo yum -y install    cmake

sudo yum -y install    cpp

sudo yum -y install    curl-devel

sudo yum -y install    elfutils-libelf-devel

sudo yum -y install    expat-devel

sudo yum -y install    gcc-c++

sudo yum -y install    gd-devel

sudo yum -y install    git

sudo yum -y install    jemalloc-devel

sudo yum -y install    libIDL-devel

sudo yum -y install    libc-client-devel

sudo yum -y install   libcap-devel

sudo yum -y install    libevent-devel

sudo yum -y install    libicu-devel

sudo yum -y install    libmcrypt-devel

sudo yum -y install    libmemcached-devel

sudo yum -y install    libtool

sudo yum -y install    libxml2-devel

sudo yum -y install    make

sudo yum -y install    memcached

sudo yum -y install    mysql-devel

sudo yum -y install    oniguruma-devel

sudo yum -y install    openldap-devel

sudo yum -y install    pam-devel

sudo yum -y install    patch

sudo yum -y install    pcre-devel

sudo yum -y install    readline-devel

sudo yum -y install    svn

sudo yum -y install    wget

sudo yum -y install    libxslt-devel

sudo yum -y install    ImageMagick-devel

5:  Checkout HHVM and Submodules

Lets checkout in /usr/local/src ( Not compulsory to check it out here)

Do the following

cd /usr/local/src

sudo git clone git://github.com/facebook/hhvm.git

cd hhvm

sudo git checkout HHVM-3.3

sudo git submodule update --init –recursive

export CMAKE_PREFIX_PATH=`pwd`/..

cd /

Now we just check the source, we can come back to installation later. Before that we need some more dependenciies for the HHVM . Lets install that .

6:  Install Intel Thread Building Blocks (tbb) (4.0 or newer)

Lets install in the same /usr/local/src

cd /usr/local/src

sudo wget        https://www.threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb42_20130725oss_src.tgz

sudo tar zxvf tbb42*.tgz

cd tbb42*

cd src

sudo make  

cd ..

sudo mkdir -p /usr/include/serial

sudo cp -a include/serial/* /usr/include/serial/

sudo mkdir -p /usr/include/tbb

sudo cp -a include/tbb/* /usr/include/tbb/

sudo cp build/linux_intel64*/libtbb.so.2 /usr/lib64/

sudo ln -s /usr/lib64/libtbb.so.2 /usr/lib64/libtbb.so

cd ..

7:  Install libDwarf

Lets install in the same /usr/local/src

sudo git clone git://git.code.sf.net/p/libdwarf/code libdwarf

cd libdwarf/libdwarf

sudo git checkout 2346f43f57f0ae768adffa55ea84b281d3aa71da

sudo ./configure

sudo make

sudo cp libdwarf.a /usr/lib64/

sudo cp libdwarf.h /usr/include/

sudo cp dwarf.h /usr/include/

cd ../..

8: Install Google glog

Lets install in the same /usr/local/src

sudo wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz

sudo tar zxvf glog-0.3.3.tar.gz

sudo svn checkout http://google-glog.googlecode.com/svn/trunk/ google-glog

cd google-glog

sudo ./configure –prefix=/usr

sudo make

sudo make install

cd ..

9:  Refreshing library cache.

First Refreshing library cache. Just run the following commend

sudo ldconfig

10:  Building HHVM

Make sure we are in /usr/local/src where we checkout the HHVM ealier

then do the following

cd hhvm

sudo cmake .

sudo make  (this is a lengthy process may consume 1 -2hour :( )

sudo make install

Now your HHVM installation is complete. Since it is from the source , we need to create some files manually . Lets do that now

10-1:  Create a file at /etc/init.d/hhvm

Before that remember where we installed the HHVM , to find that use

whereis hhvm

we may get an output as

hhvm: /usr/local/bin/hhvm

Remember this path , we need this in next step

Now Create a HHVM file in /etc/init.d/h

cd /etc/init.d

sudo vim hhvm

then paste the following code in that

#! /bin/sh

test -x /usr/local/bin/HHVM || exit 0

case "$1" in

start)

        /usr/local/bin/HHVM --config /etc/hhvm/server.hdf --user www-data --mode daemon

       ;;

  stop)

        start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/hhvm/pid

        ;;

  reload|force-reload|restart|try-restart)

       $0 stop

        $0 start

        ;;

  status)

        echo "No status"

       ;;

  *)

        echo "Usage: /etc/init.d/HHVM {start|stop|restart|status}"

        exit 1

esac

exit 0

Please note that in the above code I have used /usr/local/bin/HHVM in two places. Dont forget to give your HHVM installed path here. I.E. the path we just checked earlier using where is HHVM command.

Save the file.

Also the above code have two another files mentioned /etc/hhvm/server.hdf and /var/run/hhvm/pid

We are next coming to that files.

10-2:  Create a file /etc/hhvm/server.hdf  

Now, we need to create the /etc/hhvm/server.hdf file.

sudo mkdir hhvm

sudo vim /etc/hhvm/server.hdf

Paste the following code in it and save.

PidFile = /var/run/hhvm/pid

Server {

  SourceRoot = /var/www/html

   DefaultDocument = index.php

  Type=fastcgi

  Port=9000

  PathDebug =false

}

VirtualHost {

 * {

   Pattern = ^(.*)

   ServerVariables {

     PHP_SELF = /index.php

     SCRIPT_NAME = /index.php

   }

   RewriteRules {

     * {

       pattern = ^(.*)

       to = ^(.*) index.php?do=/$1

       qsa = true

       }

   }

 }

}

#include "/usr/share/hhvm/hdf/static.mime-types.hdf"

StaticFile {

 FilesMatch {

   * {

     pattern = .*\.(dll|exe)

     headers {

       * = Content-Disposition: attachment

     }

   }

 }

 Extensions : StaticMimeTypes

}

ErrorHandling {

   CallUserHandlerOnFatals = true

   NoInfiniteRecursionDetection = false

   ThrowBadTypeExceptions = false

   ThrowTooManyArguments = false

   WarnTooManyArguments = false

   ThrowMissingArguments = false

   ThrowInvalidArguments = false

   EnableHipHopErrors = true

   NoticeFrequency = 1    # 1 out of these many notices to log                                                                                         

   WarningFrequency = 1   # 1 out of these many warnings to log                                                                                        

   AssertActive = false

   AssertWarning = false

 }

Repo {

 Central {

   Path = /var/log/hhvm/.hhvm.hhbc

 }

}

Log {

 Level = Error

 AlwaysLogUnhandledExceptions = true

 RuntimeErrorReportingLevel = 8191

 UseLogFile = true

 UseSyslog = false

 File = /var/log/hhvm/error.log

 Access {

   * {

     File = /var/log/hhvm/access.log

     Format = %h %l %u % t \"%r\" %>s %b

   }

 }

}


MySQL {

 TypedResults = false

}

In the above file make sure SourceRoot = your Apache webservice root .In my case it is SourceRoot = /var/www/html . I am going to place all my application/project/php files inside this .

Now Just save this file. We need to comeback to this file for our HHVM configuration with PHP. Please note that this file is including a new file

/usr/share/hhvm/hdf/static.mime-types.hdf . We dont have such a file now , so we need to create that . Before that just save this edited file.

10-3:  Create a /usr/share/hhvm/hdf/static.mime-types.hdf

Now create /usr/share/hhvm/hdf/static.mime-types.hdf

cd /usr/share

sudo mkdir hhvm

cd hhvm

sudo mkdir hdf

cd hdf

sudo vim static.mime-types.hdf

Now place , the following code in that and save

StaticMimeTypes {

 ai = application/postscript

 aif = audio/x-aiff

 aifc = audio/x-aiff

 aiff = audio/x-aiff

 asc = text/plain

 atom = application/atom+xml

 au = audio/basic

 avi = video/x-msvideo

 bcpio = application/x-bcpio

 bin = application/octet-stream

 bmp = image/bmp

 cab = application/vnd.ms-cab-compressed

 cdf = application/x-netcdf

 cgm = image/cgm

 class = application/octet-stream

 cod = application/vnd.rim.cod

 cpio = application/x-cpio

 cpt = application/mac-compactpro

 csh = application/x-csh

 css = text/css

 dcr = application/x-director

 dir = application/x-director

 djv = image/vnd.djvu

 djvu = image/vnd.djvu

 dll = application/octet-stream

 dmg = application/octet-stream

 dms = application/octet-stream

 doc = application/msword

 docx = application/vnd.openxmlformats-officedocument.wordprocessingml.document

 dotx = application/vnd.openxmlformats-officedocument.wordprocessingml.template

 dtd = application/xml-dtd

 dvi = application/x-dvi

 dxr = application/x-director

 eps = application/postscript

 etx = text/x-setext

 exe = application/x-msdownload

 ez = application/andrew-inset

 flv = video/x-flv

 gif = image/gif

 gram = application/srgs

 grxml = application/srgs+xml

 gtar = application/x-gtar

 gz  = application/x-gzip

 hdf = application/x-hdf

 hqx = application/mac-binhex40

 htm  = text/html; charset=UTF-8

 html = text/html; charset=UTF-8

 ice = x-conference/x-cooltalk

 ico = image/x-icon

 ics = text/calendar

 ief = image/ief

 ifb = text/calendar

 iges = model/iges

 igs = model/iges

 jad = text/vnd.sun.j2me.app-descriptor

 jar = application/java-archive

 jnlp = application/x-java-jnlp-file

 jpe = image/jpeg

 jpeg = image/jpeg

 jpg = image/jpeg

 js = text/javascript

 kar = audio/midi

 latex = application/x-latex

 lha = application/octet-stream

 lzh = application/octet-stream

 m3u = audio/x-mpegurl

 m4u = video/vnd.mpegurl

 man = application/x-troff-man

 manifest = text/cache-manifest

 mathml = application/mathml+xml

 me = application/x-troff-me

 mesh = model/mesh

 mid = audio/midi

 midi = audio/midi

 mif = application/vnd.mif

 mov = video/quicktime

 movie = video/x-sgi-movie

 mp2 = audio/mpeg

 mp3 = audio/mpeg

 mp4 = video/mp4

 mpe = video/mpeg

 mpeg = video/mpeg

 mpg = video/mpeg

 mpga = audio/mpeg

 ms = application/x-troff-ms

 msh = model/mesh

 msi  = application/x-msi

 mxu = video/vnd.mpegurl

 nc = application/x-netcdf

 oda = application/oda

 ogg = application/ogg

 pbm = image/x-portable-bitmap

 pdb = chemical/x-pdb

 pdf = application/pdf

 pgm = image/x-portable-graymap

 pgn = application/x-chess-pgn

 png = image/png

 pnm = image/x-portable-anymap

 potx = application/vnd.openxmlformats-officedocument.presentationml.template

 ppm = image/x-portable-pixmap

 ppsx = application/vnd.openxmlformats-officedocument.presentationml.slideshow

 ppt = application/vnd.ms-powerpoint

 pptx = application/vnd.openxmlformats-officedocument.presentationml.presentation

 ps = application/postscript

 qt = video/quicktime

 ra = audio/x-pn-realaudio

 ram = audio/x-pn-realaudio

 ras = image/x-cmu-raster

 rdf = application/rdf+xml

 rgb = image/x-rgb

 rm = application/vnd.rn-realmedia

 roff = application/x-troff

 rtf = text/rtf

 rtx = text/richtext

 sgm = text/sgml

 sgml = text/sgml

 sh = application/x-sh

 shar = application/x-shar

 silo = model/mesh

 sit = application/x-stuffit

 skd = application/x-koan

 skm = application/x-koan

 skp = application/x-koan

 skt = application/x-koan

 sldx = application/vnd.openxmlformats-officedocument.presentationml.slide

 smi = application/smil

 smil = application/smil

 snd = audio/basic

 so = application/octet-stream

 spl = application/x-futuresplash

 src = application/x-wais-source

 sv4cpio = application/x-sv4cpio

 sv4crc = application/x-sv4crc

 svg = image/svg+xml

 swf = application/x-shockwave-flash

 t = application/x-troff

 tar = application/x-tar

 tcl = application/x-tcl

 tex = application/x-tex

 texi = application/x-texinfo

 texinfo = application/x-texinfo

 tgz = application/x-tar

 tif = image/tiff

 tiff = image/tiff

 tr = application/x-troff

 tsv = text/tab-separated-values

 txt = text/plain

 ustar = application/x-ustar

 vcd = application/x-cdlink

 vrml = model/vrml

 vxml = application/voicexml+xml

 wav = audio/x-wav

 wbmp = image/vnd.wap.wbmp

 wbxml = application/vnd.wap.wbxml

 wml = text/vnd.wap.wml

 wmlc = application/vnd.wap.wmlc

 wmls = text/vnd.wap.wmlscript

 wmlsc = application/vnd.wap.wmlscriptc

 wrl = model/vrml

 xbm = image/x-xbitmap

 xht = application/xhtml+xml

 xhtml = application/xhtml+xml

 xls = application/vnd.ms-excel

 xlsx = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

 xltx = application/vnd.openxmlformats-officedocument.spreadsheetml.template

 xml = application/xml

 xpi  = application/x-xpinstall

 xpm = image/x-xpixmap

 xsl = application/xml

 xslt = application/xslt+xml

 xul = application/vnd.mozilla.xul+xml

 xwd = image/x-xwindowdump

 xyz = chemical/x-xyz

 zip = application/zip

}

save this file.

Now we need to create two more folders

/var/run/HHVM

/var/log/HHVM

10-4:  Create two directories /var/log/HHVM  and /var/run/hhvm

sudo mkdir /var/log/hhvm

sudo mkdir /var/run/hhvm

Now we created almost all the required files for HHVM.

10-5:   HHVM to Listen to a Port 9000

Now the important thing , ask HHVM to listen to a port . We are using the port 9000. make sure port 9000 is available in AWS.

We are make use of our previous installed fastcgi module for this

/usr/local/bin/HHVM --mode server -vServer.Port=9000 -vServer.Type=fastcgi &

when you run this you may get an output as follows

[[email protected] /]$ /usr/local/bin/HHVM --mode server -vServer.Port=9000 -vServer.Type=fastcgi &

[1] 10560

[[email protected] /]$ mapping self...

mapping self took 0'00" (7269 us) wall time

loading static content...

loading static content took 0'00" (1 us) wall time

page server started

all servers started

Unable to open pid file www.pid for write

Dont mind the last error above. Just leave it . But make sure that after this HHVM is listening to the port. To check that use the following.

ps aux | grep hhvm

You may get an output as follows:

[[email protected] /]$ ps aux | grep hhvm

ec2-user 10560  3.8  1.5 633792 58348 pts/0    Sl   04:51   0:01 /usr/local/bin/HHVM --mode server -vServer.Port=9000 -vServer.Type=fastcgi

ec2-user 10565  0.0  0.0 110448   888 pts/0    S+   04:52   0:00 grep --color=auto hhvm

Also try

sudo fuser -v 9000/tcp

this will output as

[[email protected] /]$  sudo fuser -v 9000/tcp

           USER        PID ACCESS COMMAND

9000/tcp:            root      10619 F.... hhvm

This shows that our installed HHVM is start listening to the port 9000. Good !

10-6:   Run HHVM

Now we need to run HHVM . For that we need to change the permission of /etc/init.d/HHVM file to a super permission. Use the following commend

sudo chmod +x /etc/init.d/hhvm

Now we can run HHVM using HHVM service.

use

sudo /etc/init.d/HHVM restart

or use

sudo service HHVM start

You may get output as

[[email protected] /]$ sudo /etc/init.d/HHVM restart

/etc/init.d/hhvm: line 10: start-stop-daemon: command not found

Possible bad config node: ErrorHandling.ThrowBadTypeExceptions

Possible bad config node: ErrorHandling.ThrowTooManyArguments

Possible bad config node: ErrorHandling.ThrowMissingArguments

Possible bad config node: ErrorHandling.ThrowInvalidArguments
[[email protected] /]$ sudo service HHVM start

Possible bad config node: ErrorHandling.ThrowBadTypeExceptions

Possible bad config node: ErrorHandling.ThrowTooManyArguments

Possible bad config node: ErrorHandling.ThrowMissingArguments

Possible bad config node: ErrorHandling.ThrowInvalidArguments

Please don’t mind about the errors its outputting. This will not cause any harm to your installation or configuration. We can confirm whether HHVM is working or not via a PHP file.

10-7:   Test HHVM

For that create a checkhhvm.php file inside your project root folder. In my case it is var/www/html. So I am creating a checkhhvm.php file inside that.

sudo vim /var/www/html/checkhhvm.php

Add the following to this file

<?php

if (defined('HHVM_VERSION')) {

echo 'HHVM is working';

phpinfo();

}

else {

echo 'HHVM is not working';

}

     ?>

The run this file via HHVM as follows

hhvm/var/www/html/checkhhvm.php

if you get an output like this . We are done !!!!

[[email protected] /]$ HHVM /var/www/html/checkhhvm.php

HHVM is workingHipHop

10-8:   Enable HHVM to talk with Apache (setup a virtual host)

Now check what is the output of this file when you access via browser ?

For that just load this page via any browser If your in a local machine , then localhost/checkhhvm.php or 127.0.0.1/checkhhvm.php will help or if you are in a server use the server ip or domain.

When you view the output the most disappointing thing is it says

HHVM is not working

Don’t Worry 🙂 . We have the solution . This is because our Apache is still running on PHP and we have not requested HHVM to take that place. We need to ask HHVM to look all our PHP files . For that we need to create a virtual host in our Apache config file .

So open the httpd.conf file

  sudo vim  /etc/httpd/conf/httpd.conf  (this is my conf file path..pls use your's)

then on that file look for something like this

#<VirtualHost *:80>

#    ServerAdmin [email protected]

#    DocumentRoot /www/docs/dummy-host.example.com

#    ServerName dummy-host.example.com

#    ErrorLog logs/dummy-host.example.com-error_log

#    CustomLog logs/dummy-host.example.com-access_log common

#</VirtualHost>

below that add our virtual host as follows

<VirtualHost *:80>

  DirectorySlash On

  DirectoryIndex index.php

DocumentRoot /var/www/html/

  ProxyRequests On

  ProxyPreserveHost On

  ProxyVia full

# ProxyPass / fcgi://127.0.0.1:9000/var/www/html/

  ProxyPassMatch ^/(.+\.(hh|php)(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1

ErrorLog /var/log/httpd/hiphop.error.log

</VirtualHost>

Now just reload your page . It will say Hiphop is running !

This line in the virtual host is requesting the HHVM to take care of all the PHP files in our root folder with the help of fastcgi module

ProxyPassMatch ^/(.+\.(hh|php)(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1

make sure the following 9000 is the HHVM port and /var/www/html/ is my root folder.

So successfully run the HHVM on our checkhhvm.php file .  Now how to run our full application via this HHVM ? Lets see that .

10-9:   Run our full application via this HHVM

For an application , we may have different types of URL formats.

For example,

www.domain.com/index.php

http://example.com/index.php?q=about

http://example.com/index.php?do=about

www.domain.com/mypage

These URLs are handled in the server.hdf file of HHVM.
Lets examine that open the file

sudo vim /etc/hhvm/server.hdf.

In that we can find

Server {
SourceRoot = /var/www/html
DefaultDocument = index.php
Type=fastcgi
Port=9000
PathDebug =false
}

SourceRoot is the root of your webappilcation. In my case it is var/www/html
DefaultDocument = index.php , the first file to load .
Type=fastcgi , HHVM seking the help of fastcgi module to talk with apache
Port=9000 , the port in which the HHVM is listening
Now lets examine the next major part of the file

VirtualHost {
*{
Pattern = ^(.*)
ServerVariables {
PHP_SELF = /index.php
SCRIPT_NAME = /index.php
}
RewriteRules
{

*{
pattern = ^(.*)
to = ^(.*) index.php?do=/$1
qsa = true
}
}
}

pattern = ^(.*) , this is a pregmatch for files to load , this pattern will load all types
to = ^(.*) index.php?do=/$1 , this is an important one. It determines which all the URL format
of our application are to be handled by HHVM. Here in the example it says index.php?do
type URLs are to be handled. You can find the rewrite URL of your application from the
htaccess file of your application. Just check for RewriteRules in your htaccess and copy
the same to here.

That’s all … From now you can experience the power of HHVM.  

Learn More From Our Techies

Latest Post

Get a free quote