Friday, December 24, 2010

HipHop for PHP をインストールして apache で proxy してみた


依存関係が相当面倒なので、rpm が用意されている CentOS 5 にインストールすることにした。
CentoOS 5系であれば、以下のようなページも用意されている。
https://github.com/facebook/hiphop-php/wiki/Installing-or-Building-HipHop-PHP-via-RPM-on-CentOS-5
それでも相当いろんなパッケージを入れないといけない。

説明のとおり、yum の設定用パッケージなどを以下のとおり実行
[sikaku@localhost hiphop_rpm]$ sudo rpm -ivh http://epel.osuosl.org/5/x86_64/epel-release-5-4.noarch.rpm
[sikaku@localhost hiphop_rpm]$ sudo rpm -ivh http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/ius-release-1.0-6.ius.el5.noarch.rpm
[sikaku@localhost hiphop_rpm]$ sudo rpm -ivh http://pkg.tag1consulting.com/hphp/x86_64/hphp-release-1.0-2.el5.noarch.rpm
[sikaku@localhost hiphop_rpm]$ sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm
[sikaku@localhost hiphop_rpm]$ sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
[sikaku@localhost hiphop_rpm]$ sudo rpm -Uvh http://centos.alt.ru/repository/centos/5/x86_64/centalt-release-5-3.noarch.rpm
[sikaku@localhost hiphop_rpm]$ sudo rpm -Uvh http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
[sikaku@localhost hiphop_rpm]$ sudo yum update
以下のとおり、大量に yum でパッケージを入れる。 何度もエラーと戦い続けて、以下が必要なことがわかった。
[sikaku@localhost hiphop_rpm]$ sudo yum install libidn-devel openssl-devel cvs cvsps gcc gcc-c++ libmcrypt zlib-devel automake libmcrypt mhash libtidy mysql
[sikaku@localhost hiphop_rpm]$ sudo yum install cmake mysql-devel pcre-devel gd-devel expat-devel libmcrypt-devel libcap-devel binutils-devel flex tbb-devel
以下に用意されているパッケージを全部ダウンロードする。
http://sourceforge.net/projects/hphp/files/CentOS%205%2064bit/
このダウンロードは、Irvine などでリンクインポートして一括ダウンロードすると良い。
mysqlのライブラリが古いと、エラーが出るので以下だけ、直接 mysql からダウンロードしてくる。
[sikaku@localhost hiphop_rpm]$ wget "http://dev.mysql.com/get/Downloads/MySQL-5.1/MySQL-shared-community-5.1.54-1.rhel5.x86_64.rpm/from/http://ftp.jaist.ac.jp/pub/mysql/"
で、以下のとおりインストール。一部ダウンロードしたファイルで、依存関係が問題で入らないのがあったので、除外している。
[sikaku@localhost hiphop_rpm]$ sudo rpm -Uvh hiphop-php-1.0-2.x86_64.rpm  boost-1.37.0-1.x86_64.rpm libicu-4.2.1-6.x86_64.rpm oniguruma-5.9.2-1.x86_64.rpm php52-5.2.12-1.ius.x86_64.rpm php52-cli-5.2.12-1.ius.x86_64.rpm php52-common-5.2.12-1.ius.x86_64.rpm tbb-2.2-1.20090809.x86_64.rpm php52-mysql-5.2.12-1.ius.x86_64.rpm MySQL-shared-community-5.1.54-1.rhel5.x86_64.rpm php52-pdo-5.2.12-1.ius.x86_64.rpm libxml2-*.rpm boost-devel-1.37.0-1.x86_64.rpm libevent-*.rpm php52-gd-5.2.12-1.ius.x86_64.rpm curl-devel-7.20.0-1hiphop.x86_64.rpm curl-7.20.0-1hiphop.x86_64.rpm icu-4.2.1-6.x86_64.rpm libicu-devel-4.2.1-6.x86_64.rpm oniguruma-devel-5.9.2-1.x86_64.rpm flex-2.5.35-7.x86_64.rpm
実際に実行してみた。vm環境で 256M しか割り当ててなかったからか、スワップしまくって7分もかかった。
[sikaku@localhost dev]$ cat test.php
<?php
 echo "hello world!";
?>
[sikaku@localhost dev]$ time hphp test.php
hello world!
real    7m8.916s
user    1m2.269s
sys     0m33.538s
[sikaku@localhost dev]$
ポート8999 で起動してみる。
[sikaku@localhost dev]$ mkdir bin
[sikaku@localhost dev]$ time hphp test.php --keep-tempdir=1 -o bin
hello world!
real    9m0.035s
user    1m5.599s
sys     0m34.827s
[sikaku@localhost dev]$ bin/program -m server -p 8999
Could not mlockall
loading static content...
loading static content took 0'00" (0 ms) wall time
page server started
admin server started
all servers started
以下のようにアクセスできる。
[sikaku@localhost ~]$ curl "http://localhost:8999/test.php"
hello world!
続いて、apache の設定を以下のように追加する。mod_rewrite か、mod_proxy で proxy 設定を書く。
[sikaku@localhost dev]$ cat /etc/httpd/conf.d/custom.conf
#RewriteEngine on
#RewriteRule /(.*) http://localhost:8999/$1 [P,L]
ProxyPassMatch ^/(.*)$ http://localhost:8999/$1
[sikaku@localhost dev]$ sudo /etc/init.d/httpd restart
80 ポートからアクセスできた。
[sikaku@localhost ~]$ curl "http://localhost/test.php"
hello world!

No comments:

Post a Comment