在CentOS 6.5编译安装HHVM

警告:依据经验,如果一切顺利的话,安装估计会耗时6小时以上。编译gcc, boost, hhvm最耗时间,gcc估计1h+, boost估计0.5h+, hhvm 2.5h+. 有些下载也很耗时间,自己找办法加速。可以在吃饭/睡觉时执行编译操作。hhvm 3.1 用gcc 4.7编译是可以,但如果要用hhvm3.3则要用gcc4.8以上了。

必装的软件包

yum install git svn cpp make autoconf automake python-devel libtool patch memcached gcc-c++ cmake wget boost-devel mysql-devel pcre-devel gd-devel libxml2-devel libxslt-devel expat-devel libicu-devel bzip2-devel oniguruma-devel openldap-devel readline-devel libc-client-devel libcap-devel binutils-devel pam-devel elfutils-libelf-devel elfutils-libelf-devel-static ImageMagick-devel libevent-devel 
  • note: ImageMagick version 5.7+ is needed. you can get a more recent version from remi:
yum install ImageMagick-last* --enablerepo=remi

libmcrypt Although CentOS doesn't provide libmcrypt, we can borrow from another repo and get the files we need.

cd ~/dev
wget 'http://pkgs.repoforge.org/libmcrypt/libmcrypt-devel-2.5.7-1.2.el6.rf.x86_64.rpm'
wget 'http://pkgs.repoforge.org/libmcrypt/libmcrypt-2.5.7-1.2.el6.rf.x86_64.rpm'
rpm -Uhv libmcrypt-*.rpm

Installing GCC 4.7

The version of GCC which comes with CentOS is too old for the C++11 features used by HipHop. Either find another RPM from a nearby distro. Hip-Hop requires GCC min version 4.7

1. build & install gmp:
wget https://gmplib.org/download/gmp/gmp-5.1.3.tar.bz2
tar jxf gmp-5.1.3.tar.bz2 && cd gmp-5.1.3/
./configure --prefix=/usr/local/gmp
make && make install
cd ..
2. build & install mpfr:
wget http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.bz2
tar jxf mpfr-3.1.2.tar.bz2 ;cd mpfr-3.1.2/
./configure --prefix=/usr/local/mpfr -with-gmp=/usr/local/gmp
make && make install 
cd ..
3. build & install mpc:
wget http://www.multiprecision.org/mpc/download/mpc-1.0.1.tar.gz
tar xzf mpc-1.0.1.tar.gz ;cd mpc-1.0.1
./configure --prefix=/usr/local/mpc -with-mpfr=/usr/local/mpfr -with-gmp=/usr/local/gmp
make &&make install
cd ..

After build & install these libs, you could start to build & Install gcc4.7.3:

4. build & install gcc 4.7.3
wget http://ftp.gnu.org/gnu/gcc/gcc-4.7.3/gcc-4.7.3.tar.bz2
tar jxf gcc-4.7.3.tar.bz2 ;cd gcc-4.7.3
./configure --prefix=/usr/local/gcc -enable-threads=posix -disable-checking -disable-multilib -enable-languages=c,c++ -with-gmp=/usr/local/gmp -with-mpfr=/usr/local/mpfr/ -with-mpc=/usr/local/mpc/
if
[ $? -eq 0 ];then
echo "this gcc configure is success"
else
echo "this gcc configure is failed"
fi
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/
make -j4 //这个过程需要30-120分钟的时间,依据电脑配置而定。j4,是四个作业一块运行,从而提升编译效率。
make install
[ $? -eq 0 ] && echo install success
  1. set up the gcc env:
vi /etc/ld.so.conf.d/gcc-4.7.3.conf

Paste the following lines

/usr/local/gcc/lib/
/usr/local/mpc/lib/
/usr/local/gmp/lib/
/usr/local/mpfr/lib/

Reload Config

ldconfig

Move Old GCC and Replace With New Version

mv /usr/bin/gcc  /usr/bin/gcc_old
mv /usr/bin/g++  /usr/bin/g++_old
mv /usr/bin/c++ /usr/bin/c++_old
ln -s -f /usr/local/gcc/bin/gcc  /usr/bin/gcc
ln -s -f /usr/local/gcc/bin/g++  /usr/bin/g++
ln -s -f /usr/local/gcc/bin/c++ /usr/bin/c++
cp /usr/local/gcc/lib64/libstdc++.so.6.0.17 /usr/lib64/.
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
ln -s -f /usr/lib64/libstdc++.so.6.0.17 /usr/lib64/libstdc++.so.6
  1. finished.

you could run gcc --version to check if the current gcc version is gcc4.7.3, and also need to check g++, to see if the version is changed to g++4.7.3 too.

Installing CMake

The version of CMake which comes with CentOS6.3 is too old for the latest HHVM which requires CMake version >= 2.8.7. Either find another RPM from a nearby distro, or try using @jackywei's instructions for installing CMake 2.8.10.2 from https://github.com/jackywei/HOW-TO-BUILD-HHVM-WiKi/wiki/Build-&-Install-CMake-2.8.10.2-in-CentOS6.3

Download CMake 2.8.10.2 from http://www.cmake.org/cmake/resources/software.html#latest
cd /usr/local
tar -zxf cmake-2.8.10.2.tar.gz
rpm -qa|grep ncurses-devel // to check if you installed ncurses-devel, if not, please install this firstly
rm -f cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2
./configure
make
make install
cd ..
mv cmake-2.8.10.2 cmake
vi /etc/profile

Put below 2 lines into the bottom line of /etc/profile:

      PATH=/usr/local/cmake/bin:$PATH

      export PATH
source /etc/profile

echo $PATH // to check if cmake in the PATH.
cmake --version // to check if the version is right, should be cmake version 2.8.10.2
DONE~~~

(This does not apply to Fedora 19.)

Getting HipHop source-code
git clone git://github.com/facebook/hhvm.git
cd hhvm
export CMAKE_PREFIX_PATH=/usr
cd ..

Building third-party libraries

libCurl

Make sure that your system time is correct, otherwise ./configure will fail.

git clone git://github.com/bagder/curl.git
cd curl
./buildconf
./configure --prefix=$CMAKE_PREFIX_PATH
make
make install
cd ..

Note: If you're building a version of cURL older than 7.28.0 (for whatever reason), you'll need to apply the patch in third-party to update it prior to the make step. cat ../hhvm/third-party/libcurl-7.22.1.fb-changes.diff | patch -p1

Google glog
svn checkout http://google-glog.googlecode.com/svn/trunk/ google-glog
cd google-glog
./configure --prefix=$CMAKE_PREFIX_PATH
make
make install
cd ..
libmemcached

There may be issues with 1.0.17. and your version of centos. If so, use 1.0.9 download form libmemcached

tar -xzvf libmemcached-1.0.9.tar.gz
cd libmemcached-1.0.9
./configure --prefix=$CMAKE_PREFIX_PATH
make
make install
cd ..
JEMalloc 3.0
wget http://www.canonware.com/download/jemalloc/jemalloc-3.5.1.tar.bz2
tar xjvf jemalloc-3.5.1.tar.bz2
cd jemalloc-3.5.1
./configure --prefix=$CMAKE_PREFIX_PATH
make
make install
cd ..
Boost 1.50

Verified Boost1.50 is more like a must to have for HHVM build in CentOS5.2/6.3.

Before you build the boost, please set your HHVM env., like CMAKE_PREFIX_PATH.

wget http://sourceforge.net/projects/boost/files/boost/1.50.0/boost_1_50_0.tar.gz/download -O boost_1_50_0.tar.gz
tar -zxvf boost_1_50_0.tar.gz
cd boost_1_50_0/
./bootstrap.sh --prefix=$CMAKE_PREFIX_PATH --libdir=$CMAKE_PREFIX_PATH/lib
./bjam --layout=system install
export Boost_LIBRARYDIR=$CMAKE_PREFIX_PATH/include/boost/
ImageMagick

http://www.imagemagick.org/script/install-source.php#unix

yum install ImageMagick-last-devel ImageMagick-last

tbb and libdwarf

As of this writing, libdwarf is not available with CentOS 6.3, and the version of libtbb is much too old. Both these packages also suffer the problem of not having install targets, so getting them on your system is a bit more cumbersome.

tbb
wget 'http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20120613oss_src.tgz'
tar -zxf tbb40_20120613oss_src.tgz
cd tbb40_20120613oss
make

mkdir -p /usr/include/serial
cp -a include/serial/* /usr/include/serial/

mkdir -p /usr/include/tbb
cp -a include/tbb/* /usr/include/tbb/

cp build/linux_intel64_gcc_cc4.7.3_libc2.12_kernel2.6.32_release/libtbb.so.2 /usr/lib64/
ln -s /usr/lib64/libtbb.so.2 /usr/lib64/libtbb.so
cd ..

The exact path to your generated libtbb.so.2 may be slightly different depending on your version of gcc, libc, and the kernel, but that should be close.

libdwarf
git clone git://libdwarf.git.sourceforge.net/gitroot/libdwarf/libdwarf
cd libdwarf/libdwarf
git checkout 2346f43
./configure
make
cp libdwarf.a /usr/lib64/
cp libdwarf.h /usr/include/
cp dwarf.h /usr/include/
cd ../..

不知怎么回事,必须用2346f43的版本才能成功编译! Refreshing library cache

ldconfig

Building HHVM

cd hhvm
git submodule update --init --recursive
git checkout HHVM-3.1.0
cmake .
make -j4 //这个过程需要30-120分钟的时间,依据电脑配置而定。j4,是四个作业一块运行,从而提升编译效率。

请先使用cmake -LA看看包的路径是否正确: 修改CMakeCache.txt里面boost的路径 find /usr|grep boost 查看里面的具体信息 一般是将/usr/lib64改为/usr/lib, so话,-mt去掉 如果存在文件,又路径对不上,用链接: ln -s -f use_file target_file

Running programs

The hhvm binary can be found in hphp/hhvm/hhvm.

cp hphp/hhvm/hhvm /usr/bin/

The Hack language

See https://github.com/facebook/hhvm/wiki/Building-the-Hack-Typechecker.

参考文章