Building and Installing HHVM on CentOS 7

What's HHVM?

HHVM is an open-source virtual machine designed for executing programs written in Hackand PHP. HHVM uses a just-in-time (JIT) compilation approach to achieve superior performance while maintaining the flexibility that PHP developers are accustomed to. To date, HHVM (and its predecessor HPHPc before it) 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.

HHVM runs much of the world’s existing PHP. Developers and hosts are adopting HHVM. We are aware of minor incompatibilities (please open issues when you find them), but we can run the top 20 Github PHP frameworks out of the box. The HHVM team, along with many wonderful community members, has made it a stated, high priority goal to run all existing PHP code existing out in the wild.


You must compile the source code in a PC or VPS with RAM >= 2GB.

Or you can download the compiled version

After downloaded the compiled version, please exact it to /tmp.


We are not using sudo here because it makes the columns so long. Do it yourself or just be root here, for a short while.

First of all, you need something from epel and remi:

rpm -Uvh
rpm -Uvh # ImageMagick

Then get some development packages:

# Use bash brace extension here or the list would be really frightening
yum install cpp gcc-c++ cmake git psmisc {binutils,boost,jemalloc}-devel \
{sqlite,tbb,bzip2,openldap,readline,elfutils-libelf,gmp,lz4,pcre}-devel \
lib{xslt,event,yaml,vpx,png,zip,icu,mcrypt,memcached,cap,dwarf}-devel \
{unixODBC,expat,mariadb}-devel lib{edit,curl,xml2,xslt}-devel \
glog-devel oniguruma-devel inotify-tools-devel ocaml

# HHVM won't build without ImageMagick from remi failing after hphp_runtime_static
yum remove ImageMagick # If it's already installed
yum install ImageMagick-last\* --enablerepo=remi # Newer one

Fix the bug for glog-devel

ln -s /usr/lib64/ /usr/lib/

Grab the Source

cd /tmp
git clone -b master  hhvm  --recursive
cd hhvm

Then build it!

# ./configure # That is a cmake wrapper, ignore it.
cmake \
-DLIBMAGICKWAND_INCLUDE_DIRS="/usr/include/ImageMagick-6" \
make -j$(($(nproc)+1)) # make with CORE_COUNT+1 threads, that would be fast. You may run out of RAM
# Test..
./hphp/hhvm/hhvm --version
# Install it..
sudo make install

Add HHVM to Services

Using systemctl:
Save following to /usr/lib/systemd/system/hhvm.service

Description=HHVM HipHop Virtual Machine (FCGI)

--config /etc/hhvm/server.ini \
--config /etc/hhvm/php.ini \
--config /etc/hhvm/config.hdf
--user nginx
--mode daemon


And do some systemctl work to make it start automatically:

systemctl enable hhvm
systemctl start hhvm
systemctl status hhvm

Using service:
Save following to /etc/init.d/hhvm

# /etc/init.d/hhvm -- startup script for HHVM FastCGI
# chkconfig: 345 26 74
# description: HHVM (aka the HipHop Virtual Machine) is an open-source virtual machine designed for executing programs written in Hack and PHP
# processname: hhvm

# Provides: hhvm
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop hhvm
# Description: HHVM (aka the HipHop Virtual Machine) is an open-source virtual machine designed for executing programs written in Hack and PHP

# Source function library.
. /etc/rc.d/init.d/functions

prog=`/bin/basename $hhvm`

test -x /usr/local/bin/hhvm || exit 1

start() {
    echo -n $"Starting $prog: "

    daemon --pidfile ${pidfile} ${hhvm} --config /etc/hhvm/server.ini --mode daemon
    [ $RETVAL = 0 ] && touch ${lockfile}
    return $RETVAL

stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile} ${prog}
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}

rh_status() {
    status -p ${pidfile} ${hhvm}

case "$1" in
        rh_status >/dev/null 2>&1 && exit 0



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

exit $RETVAL

Add it to service using following commands:

chkconfig --add hhvm
chkconfig hhvm on

Then you can start up HHVM using:

service hhvm start

Config HHVM

mkdir /etc/hhvm
mkdir /var/run/hhvm
sudo chown nginx:nginx /var/run/hhvm
mkdir /var/log/hhvm
sudo chown nginx:nginx /var/log/hhvm

Create config.hdf in /etc/hhvm:

ResourceLimit {
    CoreFileSize = 0          # in bytes
    MaxSocket = 10000         # must be not 0, otherwise HHVM will not start
    SocketDefaultTimeout = 5  # in seconds
    MaxRSS = 0
    MaxRSSPollingCycle = 0    # in seconds, how often to check max memory
    DropCacheCycle = 0        # in seconds, how often to drop disk cache
Log {
    Level = Info
    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
    ReadOnly = false
    ConnectTimeout = 1000      # in ms
    ReadTimeout = 1000         # in ms
    SlowQueryThreshold = 1000  # in ms, log slow queries as errors
    KillOnTimeout = false
Mail {
    SendmailPath = /usr/sbin/sendmail -t -i
    ForceExtraParameters =

Create server.ini in /etc/hhvm:

; php options
pid = /var/run/hhvm/pid
; hhvm specific
hhvm.server.port = 9001
;hhvm.server.file_socket = /var/run/hhvm/sock
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.log.use_log_file = true
hhvm.log.file = /var/log/hhvm/error.log
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc

Create php.ini in /etc/hhvm:

hhvm.mysql.socket = /tmp/mysql.sock
hhvm.server.expose_hphp = true
memory_limit = 400M
post_max_size = 50M


Contact Us
  • SenseTime Research, Shenzhen Bay Eco-Technology Park
  • cshzxie [at] gmail [dot] com