co`i blog

just another trash

HipHop PHP trên Gentoo

written by co`i , on 3/23/10 2:19 PM.

Bạn nào compile thử hphp (HipHop PHP) chắc cũng sẽ biết nỗi khổ compile một đống các thứ lỉnh kỉnh để có thể compile được. Tuy nhiên, trên gentoo mọi việc... thật đơn giản :-) Trong khi chờ đợi tôi release các file rpm đã patch theo yêu cầu của hphp trên CentOS 5.x, tôi sẽ chỉ các bạn compile trên gentoo.
Thực ra theo tôi thấy, do hphp phụ thuộc vào các lib cũng như việc compile hphp nhiều nên các bạn chọn những distro compile from source là tốt nhất. Hoặc như pdah build toàn bộ lib theo PREFIX khác với system.

Lưu ý
Hiện nay hphp chỉ chạy trên nền 64bits.
Trong hướng dẫn tôi sử dụng emerge với option -pv để các bạn biết các option tôi đã compile.

Trước hết và dĩ nhiên: sync data mới của gentoo.
emerge --sync

Cài git
Server10 ~ # emerge -v dev-vcs/git
[ebuild     U ] dev-vcs/git-1.7.0.2 [1.7.0] USE="cgi curl iconv perl subversion threads -bash-completion -blksha1 -cvs -doc -emacs -gtk (-ppcsha1) -tk -webdav -xinetd" 2,644 kB

Cài các gói kiểm tra các gói thông dụng cần cài đặt bởi hphp
Server10 ~ # emerge -pv cmake gcc flex bison re2c mysql libxml2 icu openssl binutils libcap zlib dev-libs/oniguruma expat libmcrypt gd

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] dev-libs/expat-2.0.1-r3  0 kB
[ebuild   R   ] dev-util/re2c-0.13.5  0 kB
[ebuild   R   ] dev-libs/icu-4.2.1  USE="-debug -doc -examples" 0 kB
[ebuild   R   ] dev-libs/oniguruma-5.9.2  0 kB
[ebuild   R   ] dev-libs/libmcrypt-2.5.8-r1  0 kB
[ebuild   R   ] sys-devel/flex-2.5.35  USE="nls -static" 1,228 kB
[ebuild   R   ] sys-devel/bison-2.4.1  USE="nls -static" 0 kB
[ebuild   R   ] sys-libs/libcap-2.19  USE="-pam" 0 kB
[ebuild     U ] sys-devel/binutils-2.20.1 [2.20-r1] USE="multislot* nls -multitarget -test -vanilla" 17,106 kB
[ebuild     U ] sys-libs/zlib-1.2.4 [1.2.3-r1] 473 kB
[ebuild   R   ] sys-devel/gcc-4.3.4  USE="hardened mudflap (multilib) multislot nls nptl openmp (-altivec) -bootstrap -build -doc (-fixed-point) -fortran -gcj -gtk (-libffi) (-n32) (-n64) -nocxx -nopie -objc -objc++ -objc-gc -test -vanilla" 74 kB
[ebuild     U ] dev-util/cmake-2.8.1 [2.8.0-r2] USE="ncurses -emacs -qt4 -vim-syntax" 3,522 kB
[ebuild     U ] dev-libs/openssl-0.9.8m-r1 [0.9.8l-r2] USE="kerberos* (sse2) zlib -bindist -gmp -test" 3,680 kB
[ebuild     U ] dev-libs/libxml2-2.7.7 [2.7.6] USE="python readline -debug -doc -examples -ipv6 -test" 4,755 kB
[blocks b     ] <dev-libs/libxml2-2.7.7 ("<dev-libs/libxml2-2.7.7" is blocking sys-libs/zlib-1.2.4)
[ebuild   R   ] media-libs/gd-2.0.35-r1  USE="fontconfig jpeg png truetype xpm" 0 kB
[ebuild   R   ] dev-db/mysql-5.1.44-r1  USE="big-tables cluster extraengine perl ssl -community -debug -embedded -latin1 -max-idx-128 -minimal -pbxt -profiling (-selinux) -static -test" 0 kB

Total: 16 packages (5 upgrades, 11 reinstalls), Size of downloads: 30,834 kB

Cài libmbfl: đi kèm với hphp không cần phải cài. Khi load hphp về sẽ có sẵn.
libpcre3 có sẵn trong gentoo.

Cài tbb: yêu cầu của hphp là 2.2 trở lên, bản có trên gentoo của tôi là tbb-2.1.015 không phù hợp nên phải tự tạo file ebuild mới sau đó mới emerge.
Server10 ~ # cd /usr/portage/dev-cpp/tbb
Server10 tbb # wget http://static.conlua.net/uploads/hphp/tbb-2.2.013.ebuild
Server10 tbb # ebuild tbb-2.2.013.ebuild digest
Server10 tbb # emerge -pv tbb

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] dev-cpp/tbb-2.2.013  USE="-debug -doc -examples" 0 kB

Cài Boost: có thể compile hphp với Boost 1.42, nhưng khuyến cáo dân dev-hphp, không nên chạy với Boost 1.42 do 1 số bug của Boost. Nên tôi phải downgrade xuống bản 1.41.
Server10 ~ # echo ">=dev-libs/boost-1.42.0" >> /etc/portage/package.mask
Server10 ~ # emerge -pv boost

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] dev-libs/boost-1.41.0-r3  USE="eselect expat icu mpi python tools -debug -doc -test" 0 kB

Lấy source hphp: sử dụng git để lấy source từ repo.
Server10 ~ # mkdir /usr/src/hh
Server10 ~ # cd /usr/src/hh
Server10 hh # git clone git://github.com/facebook/hiphop-php.git
Server10 hh # cd hiphop-php
Server10 hiphop-php # git submodule init
Server10 hiphop-php # git submodule update

Cài đặt libevent: hphp cần apply 1 patch riêng cho lib này, nên ta tiến hành build với patch.
Server10 ~ # mkdir /usr/portage/dev-libs/libevent/files
Server10 ~ # cd /usr/src/hh/hiphop-php/
Server10 hiphop-php # cp src/third_party/libevent.fb-changes.diff /usr/portage/dev-libs/libevent/files
Server10 hiphop-php # cd /usr/portage/dev-libs/libevent/
Server10 libevent # rm -rf libevent-1.4.13.ebuild
Server10 libevent # wget http://static.conlua.net/uploads/hphp/libevent-1.4.13.ebuild
Server10 libevent # ebuild libevent-1.4.13.ebuild digest
Server10 libevent # emerge -pv libevent

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] dev-libs/libevent-1.4.13  0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB
Trong trường hợp emerge ra version mới hơn, có thể tự đọc file download về, để ý dòng dưới đây và ghi vào vị trí tương ứng file mới. Nếu không, có thể làm tương tự việc mask packages giống như đã làm với Boost.
epatch "${FILESDIR}"/libevent.fb-changes.diff

Cài đặt curl: hphp cần apply 1 patch riêng cho lib này, nên ta tiến hành build với patch.
Server10 ~ # cd /usr/src/hh/hiphop-php/
Server10 hiphop-php # cp src/third_party/libcurl.fb-changes.diff /usr/portage/net-misc/curl/files
Server10 hiphop-php # cd /usr/portage/net-misc/curl/
Server10 curl # rm -rf curl-7.20.0-r1.ebuild
Server10 curl # wget http://static.conlua.net/uploads/hphp/curl-7.20.0-r1.ebuild
Server10 curl # ebuild curl-7.20.0-r1.ebuild digest
Server10 curl # emerge -pv curl

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] net-misc/curl-7.20.0-r1  USE="gnutls idn kerberos ldap libssh2 ssl -ares -ipv6 -nss -test" 0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB

Bắt đầu biên dịch hphp
Server10 ~ # cd /usr/src/hh/hiphop-php/
Server10 hiphop-php # export HPHP_HOME=`pwd`
Server10 hiphop-php # export HPHP_LIB=`pwd`/bin
Server10 hiphop-php # cmake .
Server10 hiphop-php # make


Ở đây tôi thử hphp với RivetTracker. Tôi làm như sau:
Server10 ~ # cd /home/rt/pub
Server10 pub # find . -name "*.php" > files.list
Server10 pub # $HPHP_HOME/src/hphp/hphp --input-list=files.list -k 1 --log=9 --force=1 --cluster-count=8
Kết quả tôi có khi compile nằm ở thư mục /tmp/hphp_HoMEOR. Tôi thử chạy và kiểm tra ứng dụng.
Server10 ~ # cd /home/rt/pub
Server10 pub # /tmp/hphp_HoMEOR/program -m server -v "Server.SourceRoot=`pwd`" -v "Server.DefaultDocument=index.php" -c $HPHP_HOME/bin/mime.hdf

Và khi dùng trình duyệt mở web theo máy chủ tôi đã cài. Kết quả ra đúng như ý muốn.

Một số thử nghiệm và kết quả
  • phpMyAdmin : không biên dịch được source C++. Báo lỗi undefined var, nếu có thời gian sửa lại source php có thể chạy được.
  • VBulletin : không biên dịch được source C++. Báo lỗi không thấy file, lỗi này do structure của các class kém của VBB.
  • wTorrent : không parse được hphp. Do sử dụng require_one nhiều chỗ. Sử dụng path tương đối.
  • WordPress : Compile được nhưng chạy không chính xác. Tôi thử không có xài patch của hphp.

Các bạn thử nhé :-)


Tham khảo:
Building and installing - hiphop-php - GitHub
Boost 1.42 - HipHop for PHP Dev - Google Groups

Comments

  • Cái này thì thế nào sourceforge.net/projects/hphp/ ? mình vẫn chưa thấy lợi hại của đồng chí này :-S

    Comment by Hếu — 3/23/10 5:59 PM | # - re

  • moi noi hoi chieu da co install guide roi a` :)

    Comment by HaiThangCu — 3/23/10 9:26 PM | # - re

  • @Heu: đó là rpm lụi tạo ra bởi make rpm. Not good for CentOS system. @2Cu: hhaha... gentoo mà :p

    Comment by co`i — 3/23/10 9:40 PM | # - re

  • À, thấy trển viết gì gì cho Centos ấy mà, nhưng tóm lại là cái này nghịch cho vui thôi, production thì vứt vào xó :-) lợi được 50% của 3% tổng thiệt hại thì chẳng thấm vào đâu so với DB I/O.

    Ah, nhỡ mai sau site lớn như FB thì sao nhỉ :D

    Comment by Hếu — 3/25/10 5:27 AM | # - re

  • @Heu: thử trước để biết lỗi :-) với có quy trình xử lý sẵn, sau này đưa vào xài ngon lành. Lợi 50% là 1 con số lớn. DB I/O đã có giải pháp rồi :-)

    Comment by co`i — 3/26/10 10:33 PM | # - re

  • hoc duoc rat nhieu

    Comment by Vomorand-online — 6/2/10 10:13 PM | # - re

Leave a Reply