背景:HipHop是Facebook在今年早些时候放出的一个php开源项目,主要的特征就是把php翻译成了c++执行,HipHop所带来的性能提升用Facebook官方博客上项目负责人赵海平的话说:
With HipHop we’ve reduced the CPU usage on our Web servers on average by about fifty percent, depending on the page. Less CPU means fewer servers, which means less overhead. This project has had a tremendous impact on Facebook.
HipHop的官网是http://github.com/facebook/hiphop-php,上面有说明了HipHop的安装步骤,但是我个人感觉那还是不够详细具体的,实际的安装过程中会碰到了不少问题。
在此我详细罗列出安装步骤和分享出解决所碰到问题的过程和方法,以便能帮助到那些喜爱php技术,想要了解HipHop的人,能对HipHop有更深层次的认识。
我的环境准备: Centos 5.5 64bit,Corei7 860,4G内存(注意:内存不能太小,HipHop在make时候和运行时候是很耗内存的;操作系统最好为64位)
开始安装:
1.切换到root账号并建立/root/bulid目录
[user@localhost ~]$ su -
[root@localhost ~]# mkdir build
[root@localhost ~]# cd build
2.安装rpmforge
[root@localhost build]# yum install yum-priorities
[root@localhost build]# wget http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
[root@localhost build]# rpm -import http://apt.sw.be/RPM-GPG-KEY.dag.txt
[root@localhost build]# rpm -K rpmforge-release-0.3.6-1.el5.rf.*.rpm
[root@localhost build]# rpm -i rpmforge-release-0.3.6-1.el5.rf.*.rpm
[root@localhost build]# yum check-update
[root@localhost build]# vim /etc/yum.repos.d/rpmforge.repo 修改enabled = 0
3.直接先用yum安装一些HipHop需要的基础包
[root@localhost build]# yum install \
binutils \
binutils-devel \
bison \
cmake \
curl-devel \
distcc \
expat \
gcc \
gcc-c++ \
gd \
gd-devel \
git \
libcap-devel \
libevent-devel \
libmcrypt-devel \
libssh2 \
libxml2-devel \
openssl-devel \
pcre-devel \
re2c \
flex \
zlib \
--enablerepo=rpmforge
4.安装perl git
[root@localhost build]# wget http://www.kernel.org/pub/software/scm/git/RPMS/x86_64/perl-Git-1.5.6.1-1.x86_64.rpm
[root@localhost build]# rpm -U perl-Git-1.5.6.1-1.x86_64.rpm
5.安装tbb
[root@localhost build]# wget http://www.threadingbuildingblocks.org/uploads/77/151/3.0/tbb30_20100406oss_lin.tgz
[root@localhost build]# tar xvzf tbb30_20100406oss_lin.tgz
[root@localhost build]# export TBB_INSTALL_DIR="/root/build/tbb30_20100406oss"
[root@localhost build]# export TBB_ARCH_PLATFORM="intel64/cc4.1.0_libc2.4_kernel2.6.16.21"
注意:我一开始cmake的时候,总会报Could NOT find TBB library的错误,分析了hiphop-php/CMake/FindTBB.cmake源码后,发现167行为:
set (TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/$ENV{TBB_ARCH_PLATFORM}/lib")
改为
set (TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/lib/$ENV{TBB_ARCH_PLATFORM}")
后即可。
因此我得出一个结论,当你配置好了环境变量而cmake的时候又提示你找不到这个lib的时候,本身的cmake文件和你下载下来的的lib不匹配就可能导致此问题,解决的办法即是直接修改cmake文件,满足符合你的需要。
当然还会有其他可能导致类似的问题,我接下去会说。
6.通过rpm包安装boost和icu库
[root@localhost build]# wget http://sourceforge.net/projects/hphp/files/CentOS%205%2064bit/RPM/boost-1.37.0-1.x86_64.rpm/download
[root@localhost build]# wget http://sourceforge.net/projects/hphp/files/CentOS%205%2064bit/RPM/boost-devel-1.37.0-1.x86_64.rpm/download
[root@localhost build]# wget http://sourceforge.net/projects/hphp/files/CentOS%205%2064bit/RPM/icu-4.2.1-6.x86_64.rpm/download
[root@localhost build]# wget http://sourceforge.net/projects/hphp/files/CentOS%205%2064bit/RPM/libicu-4.2.1-6.x86_64.rpm/download
[root@localhost build]# wget http://sourceforge.net/projects/hphp/files/CentOS%205%2064bit/RPM/libicu-devel-4.2.1-6.x86_64.rpm/download
[root@localhost build]# rpm -ivh \
icu-4.2.1-6.x86_64.rpm \
libicu-4.2.1-6.x86_64.rpmm \
libicu-devel-4.2.1-6.x86_64.rpm \
boost-1.37.0-1.x86_64.rpm \
boost-devel-1.37.0-1.x86_64.rpm
7.安装Oniguruma
[root@localhost build]# wget http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.2.tar.gz
[root@localhost build]# tar xvfz onig-5.9.2.tar.gz
[root@localhost build]# cd onig-5.9.2
[root@localhost onig-5.9.2]# ./configure && make && sudo make install
[root@localhost onig-5.9.2]# cd ..
8.下载HipHop
[root@localhost build]# git clone git://github.com/facebook/hiphop-php.git
9.安装libevent
[root@localhost build]# wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
[root@localhost build]# tar xvzf libevent-1.4.13-stable.tar.gz
[root@localhost build]# cd libevent-1.4.13-stable
[root@localhost libevent-1.4.13-stable]# cp ../hiphop-php/src/third_party/libevent-1.4.13.fb-changes.diff .
[root@localhost libevent-1.4.13-stable]# patch -p1 < libevent-1.4.13.fb-changes.diff
[root@localhost libevent-1.4.13-stable]# ./configure && make && make install
[root@localhost libevent-1.4.13-stable]# cp .libs/libevent.so /usr/lib64/libevent.so
[root@localhost libevent-1.4.13-stable]# cd ..
10.安装curl
[root@localhost build]# wget http://curl.haxx.se/download/curl-7.20.0.tar.gz
[root@localhost build]# tar xvzf curl-7.20.0.tar.gz
[root@localhost build]# cd curl-7.20.0
[root@localhost curl-7.20.0]# cp ../hiphop-php/src/third_party/libcurl.fb-changes.diff .
[root@localhost curl-7.20.0]# patch -p1 < libcurl.fb-changes.diff
[root@localhost curl-7.20.0]# ./configure && make && make install
[root@localhost curl-7.20.0]# cp .libs/libcurl.so /usr/lib64/libcurl.so
[root@localhost curl-7.20.0]# cd ..
11.安装MySQL
[root@localhost build]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.3-m3.tar.gz/from/http://mysql.he.net/
[root@localhost build]# tar zxvf mysql-5.5.3-m3.tar.gz
[root@localhost build]# cd mysql-5.5.3-m3/
[root@localhost mysql-5.5.3-m3]# ./configure --prefix=/root/bulid/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg
[root@localhost mysql-5.5.3-m3]# make && make install
[root@localhost mysql-5.5.3-m3]# cd ..
[root@localhost build]# export MYSQL_DIR="/root/bulid/mysql"
[root@localhost build]# vi hiphop-php/CMake/FindMySQL.cmake
删除33行$ENV{MYSQL_INCLUDE_DIR}
删除70行$ENV{MYSQL_DIR}/libmysql_r/.libs
删除71行$ENV{MYSQL_DIR}/lib
12.安装libmemcached,要先装memcached
[root@localhost build]# wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
[root@localhost build]# wget http://launchpad.net/libmemcached/1.0/0.42/+download/libmemcached-0.42.tar.gz
[root@localhost build]# tar zxvf memcached-1.4.5.tar.gz
[root@localhost build]# cd memcached-1.4.5
[root@localhost memcached-1.4.5]# ./configure --with-libevent=/root/build/libevent-1.4.1/
[root@localhost memcached-1.4.5]# make && make install
[root@localhost memcached-1.4.5]# cd ../libmemcached-0.42
[root@localhost libmemcached-0.42]# ./configure --with-memcached-dir=/root/build/memcached-1.4.5
[root@localhost libmemcached-0.42]# make && make install
[root@localhost libmemcached-0.42]# cd ..
13.cmake HipHop
[root@localhost build]# export CMAKE_PREFIX_PATH=/root/build
[root@localhost build]# cd hiphop-php/
[root@localhost hiphop-php]# git submodule init
[root@localhost hiphop-php]# git submodule update
[root@localhost hiphop-php]# export HPHP_HOME=`pwd`
[root@localhost hiphop-php]# export HPHP_LIB=`pwd`/bin
[root@localhost hiphop-php]# cmake .
cmake列表
-- MySQL Include dir: /root/bulid/mysql/include library dir: /root/bulid/mysql/lib/mysql
-- MySQL client libraries: mysqlclient_r
-- Found libevent: /usr/lib64/libevent.so
-- Found GD: /usr/lib64/libgd.so
-- Found ICU header files in /usr/include
-- Found ICU libraries: /usr/lib64/libicuuc.so
-- Skipping TCmalloc
-- Found Intel TBB
-- Found mcrypt: /usr/lib/libmcrypt.so
-- Looking for arpa/inet.h
-- Looking for arpa/inet.h - found
-- Looking for netinet/in.h
-- Looking for netinet/in.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for string.h
-- Looking for string.h - found
-- Looking for sys/socket.h
-- Looking for sys/socket.h - found
-- Looking for sys/time.h
-- Looking for sys/time.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of size_t
-- Check size of size_t - done
-- Check size of ssize_t
-- Check size of ssize_t - done
-- Check size of uint32_t
-- Check size of uint32_t - done
-- Check size of uint8_t
-- Check size of uint8_t - done
-- Looking for AF_LOCAL
-- Looking for AF_LOCAL - found
-- Looking for PF_LOCAL
-- Looking for PF_LOCAL - found
-- Looking for memset
-- Looking for memset - found
-- Looking for socket
-- Looking for socket - found
-- Looking for strerror
-- Looking for strerror - found
-- Found libevent: /usr/lib64/libevent.so
-- Looking for event_get_version_number
-- Looking for event_get_version_number - found.
-- Performing Test HAVE_LIBEVENT_145
-- Performing Test HAVE_LIBEVENT_145 - Success
-- Found libevent 1.4.5+
-- Looking for include files INCLUDE_CHECK_stdlib.h
-- Looking for include files INCLUDE_CHECK_stdlib.h - found
-- Looking for include files INCLUDE_CHECK_assert.h
-- Looking for include files INCLUDE_CHECK_assert.h - found
-- Looking for strcasecmp
-- Looking for strcasecmp - found
-- Looking for strchr
-- Looking for strchr - found
-- Downloading 8859-1.TXT
-- Downloading 8859-2.TXT
-- Downloading 8859-3.TXT
-- Downloading 8859-4.TXT
-- Downloading 8859-5.TXT
-- Downloading 8859-6.TXT
-- Downloading 8859-7.TXT
-- Downloading 8859-8.TXT
-- Downloading 8859-9.TXT
-- Downloading 8859-10.TXT
-- Downloading 8859-11.TXT
-- Downloading 8859-13.TXT
-- Downloading 8859-14.TXT
-- Downloading 8859-15.TXT
-- Downloading 8859-16.TXT
-- Downloading EastAsianWidth.txt
-- Looking for include files HAVE_SYS_STAT_H
-- Looking for include files HAVE_SYS_STAT_H - found
-- Looking for include files HAVE_STDLIB_H
-- Looking for include files HAVE_STDLIB_H - found
-- Looking for include files HAVE_STRING_H
-- Looking for include files HAVE_STRING_H - found
-- Looking for include files HAVE_MEMORY_H
-- Looking for include files HAVE_MEMORY_H - found
-- Looking for include files HAVE_STRINGS_H
-- Looking for include files HAVE_STRINGS_H - found
-- Looking for include files HAVE_INTTYPES_H
-- Looking for include files HAVE_INTTYPES_H - found
-- Looking for include files HAVE_UNISTD_H
-- Looking for include files HAVE_UNISTD_H - found
-- Looking for include files HAVE_DLFCN_H
-- Looking for include files HAVE_DLFCN_H - found
-- Looking for fdatasync
-- Looking for fdatasync - found
-- Looking for usleep
-- Looking for usleep - found
-- Looking for fullfsync
-- Looking for fullfsync - found
-- Looking for localtime_r
-- Looking for localtime_r - found
-- Looking for gmtime_r
-- Looking for gmtime_r - found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Check if the system is big endian
-- Searching 16 bit integer
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Looking for include files HAVE_LOCALE_H
-- Looking for include files HAVE_LOCALE_H - found
-- Looking for include files HAVE_LIMITS_H
-- Looking for include files HAVE_LIMITS_H - found
-- Check size of int32_t
-- Check size of int32_t - done
-- Looking for strtoll
-- Looking for strtoll - found
-- Looking for atoll
-- Looking for atoll - found
-- Looking for strftime
-- Looking for strftime - found
-- Looking for setlocale
-- Looking for setlocale - found
-- Configuring done
-- Generating done
-- Build files have been written to: /root/build/hiphop-php
cmake一般出错就是提示库找不到,原因出了之前说的那种外还有可能是程序找的/usr/lib/libxxx.so,而这个lib本身叫/usr/lib/libxxx.so.1,因此你需要cp一份或是ln,让程序能找得到。
14.make HipHop,离胜利仅仅一步之遥了!
[root@localhost hiphop-php]# make
make的时候很耗cpu和内存的,因此想在vps上玩HipHop的同学要注意了,有可能程序会卡死。
我在make的过程中碰到如下的错误:
追到ext_mysql.cpp的722行后看到有如下语句:
721 static Variant php_mysql_localize_result(MYSQL *mysql) {
722 mysql = mysql->last_used_con;
723 if (!mysql->fields) return true;
724 if (mysql->status != MYSQL_STATUS_GET_RESULT) {
725 // consistent with php_mysql_do_query_general
726 return true;
727 }
我查询了mysql-5.5.3的源码后,发现MYSQL的定义并没有last_used_con,结构如下:
typedef struct st_mysql
{
NET net; /* Communication parameters */
unsigned char *connector_fd; /* ConnectorFd for SSL */
char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
char *info, *db;
struct charset_info_st *charset;
MYSQL_FIELD *fields;
MEM_ROOT field_alloc;
my_ulonglong affected_rows;
my_ulonglong insert_id; /* id if insert on table with NEXTNR */
my_ulonglong extra_info; /* Not used */
unsigned long thread_id; /* Id for connection in server */
unsigned long packet_length;
unsigned int port;
unsigned long client_flag,server_capabilities;
unsigned int protocol_version;
unsigned int field_count;
unsigned int server_status;
unsigned int server_language;
unsigned int warning_count;
struct st_mysql_options options;
enum mysql_status status;
my_bool free_me; /* If free in mysql_close */
my_bool reconnect; /* set to 1 if automatic reconnect */
/* session-wide random string */
char scramble[SCRAMBLE_LENGTH+1];
my_bool unused1;
void *unused2, *unused3, *unused4, *unused5;
LIST *stmts; /* list of all statements */
const struct st_mysql_methods *methods;
void *thd;
/*
Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
from mysql_stmt_close if close had to cancel result set of this object.
*/
my_bool *unbuffered_fetch_owner;
/* needed for embedded server - no net buffer to store the 'info' */
char *info_buffer;
void *extension;
} MYSQL;
然后我google追了下mysql之前的源码,是有过存在last_used_con的时期,但是后来已经被mysql的开发人员废弃了,因此我 怀疑这个有可能是HipHop在开发的时候MYSQL的结构里还有last_used_con,但是我下载的mysql库已经没有,所以导致此问题。
我把722的mysql = mysql->last_used_con;删除后重新make就没有问题了。
还有一点需要注意的是:如果是你在cmake阶段出现的问题,但是在make阶段暴露了,你需要重新cmake的时候你需要移除hiphop-php/CMakeCache.txt文件。
到此,HipHop的安装就算告一段落,还是比较繁琐的,希望以后facebook能简化这个过程。
未来的文章里我会对HipHop的应用有持续的说明,比如它如何编译smarty,以及各种环境性能的测试比较,尽请期待!
本站文章皆为原创,如需转载,请注明出处:http://blog.liubijian.com/hiphop-php-install.html和本站声明,谢谢!