How to build HHVM 3.6 on CentOS 7
2015 UPDATE: new wiki page for HHVM on CentOS7 with alternate instructions
While building HHVM (HipHop Virtual Machine) for faster PHP on CentOS 6.x was pretty much a nightmare because almost none of third-party libraries are available from major repositories, the freshly released CentOS 7.0 solves most of this problem as it has far newer packages available from EPEL (because it has roots in more modern Fedora 19).
Note that unlike PHP/PHPNG, HHVM requires major resources to build. You may be used to making PHP in 15 minutes on a little old 256mb 1ghz box. You can forget that with HHVM which is a beast to compile. 1gb ram minimum and lots of cpu power required to keep it an hour or two (this is part of why PHP NG instead is so exciting because it will be so much easier to custom build).
I will assume you have CentOS7 setup and know how to work in bash as root. Make sure you have either the default MariaDB or MySQL installed for the libraries.
You will first need to setup the EPEL repository in yum if you have not already:
yum install epel-release
Then you need the new 4.8 compiling tools (no more devtoolset needed like CentOS 6.x) cmake 2.8 as well as git and accessories if you don’t already have them installed.
yum install gcc gcc-c++ cpp cmake git psmisc ocaml
Now you need a whole bunch of library dependencies, I think I found them all.
yum install binutils-devel boost-devel libmcrypt-devel libmemcached-devel jemalloc-devel libevent-devel sqlite-devel libxslt-devel libicu-devel tbb-devel libzip-devel bzip2-devel openldap-devel readline-devel elfutils-libelf-devel libdwarf-devel libcap-devel libyaml-devel libedit-devel lz4-devel libvpx-devel unixODBC-devel libgmp-devel libpng-devel ImageMagick-devel curl-devel expat-devel openssl-devel glog-devel oniguruma-devel
(typically installing the “devel” package will also install the parent package)
(update: glog and oniguruma was added to epel, no need to build anymore)
There are two packages left, google-glog and oniguruma, that CentOS 7.0 does not have in the main or EPEL repositories at this time unfortunately. However this is still far better than 6.x (which strangely does actually have oniguruma). So we have to build them ourselves.
tar xvzf glog-0.3.3.tar.gz
tar xvzf onig-5.9.6.tar.gz
Now we are ready to pull down the huge source code for HHVM and all of its bundled third-party libraries.
I ran into a problem when trying to checkout the 3.2 branch where it is tied to an older libzip version 0.10 which does not work with 3.2 and requires 0.11 – this specific fix was still not applied to the 3.2 branch so unless that changes by the time you read this, you need to checkout the master instead.
cd /tmp git clone https://github.com/facebook/hhvm -b master hhvm --recursive
(change -b master to -b HHVM-3.6 if they eventually fix 3.6 branch)
First do your configure and see if everything passes or if something was missed.
cd /tmp/hhvm ./configure
If it looks good, start the compile and go do something for an hour or two. If you have a multi-core machine with plenty of ram, you can try to accelerate make by telling it you have extra cores +1 (didn’t seem to work for me).
make # make -j5 (where 5 is the number of cores you have plus one or x2)
When it is finished you can check the version and have it install the various libraries, binaries and header files.
./hphp/hhvm/hhvm --version make install
Now you’ll need to setup hhvm’s server.hdf, an init.d script and update your fastcgi configuration in nginx or apache. Github is a great way to search for these items since this isn’t a packaged rpm and you have to DIY. You want newer things from hhvm 3.x instead of the old hhvm 2.x if possible.
If you want to try the new systemd way in CentOS 7 instead of init.d legacy way to start and stop hhvm, try this simple one to get started and copy it to
[Unit] Description=HHVM HipHop Virtual Machine (FCGI) [Service] ExecStart=/usr/local/bin/hhvm --config /etc/hhvm/server.hdf --user nobody --mode daemon -vServer.Type=fastcgi -vServer.Port=9000 [Install] WantedBy=multi-user.target
If hhvm is running locally instead of a remote server, you might want to change from a tcp/ip socket to a unix socket by replacing
Last you’ll need to make a config file in /etc/hhvm/server.hdf, you can also try the new php.ini format style support but be aware they still have not made all settings accessable in the ini format.
Then you can do
systemctl enable hhvm systemctl start hhvm systemctl status hhvm
Don’t forget to
mkdir /etc/hhvm mkdir /var/log/hhvm
(you will need to use /var/run/ for the pid and sock files unless you want to learn systemd-tmpfiles to create /var/run/hhvm/ automatically since /var/run/ is tmpfs in CentOS7)
You can try to find other hints, tips and tricks at the HHVM wiki on github.
I’ve also created a replacement for the missing phpinfo in hhvm here called hhvminfo
Hope that helps. Enjoy and let me know if I forgot anything.