Breaking News
Loading...
July 8, 2015

Building and Installing HHVM on CentOS 7

9:21 AM

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.

Prerequisites

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.

Prepare

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 http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm # 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/libglog.so /usr/lib/libglog.so

Grab the Source

cd /tmp
git clone https://github.com/facebook/hhvm -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" \
-DLIBMAGICKCORE_LIBRARIES="/usr/lib64/libMagickCore-6.Q16.so" \
-DLIBMAGICKWAND_LIBRARIES="/usr/lib64/libMagickWand-6.Q16.so" .
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
[Unit]
Description=HHVM HipHop Virtual Machine (FCGI)

[Service]
ExecStart=/usr/local/bin/hhvm
--config /etc/hhvm/server.ini \
--config /etc/hhvm/php.ini \
--config /etc/hhvm/config.hdf
--user nginx
--mode daemon
-vServer.Type=fastcgi
-vServer.Port=9000

[Install]
WantedBy=multi-user.target
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
#!/bin/bash
#
# /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

### BEGIN INIT INFO
# 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
### END INIT INFO

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

hhvm=/usr/local/bin/hhvm
prog=`/bin/basename $hhvm`
lockfile=/var/lock/subsys/hhvm
pidfile=/var/run/hhvm/pid
RETVAL=0

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=$?
    echo
    [ $RETVAL = 0 ] && touch ${lockfile}
    return $RETVAL
}

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

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

case "$1" in
  start)
        rh_status >/dev/null 2>&1 && exit 0
        start
        ;;
  stop)
        stop
        ;;

  reload|force-reload|restart|try-restart)
        stop
        start
        ;;

  status)
        rh_status
        RETVAL=$?
        ;;

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

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
        }
    }
}
MySQL {
    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

0 comments:

Post a Comment

 
Toggle Footer