(轉)PHP HipHop實戰之安裝篇

原文鏈接:http://blog.liubijian.com/hiphop-php-install.html

 

覺得有用,保存。。。

 

 

背景: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和本站聲明,謝謝!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章