在Ubuntu下编译安装Thrift(支持php和c++)

Thrift是一个开源的RPC框架,由知名SNS社区FaceBook贡献。下面记录了在Ubuntu 10.04下编译安装Thrift的全过程。

1、编译安装依赖
安装Java(除非你不想RPC使用Java)
[shell]
add-apt-repository "deb http://archive.canonical.com/ lucid partner"
apt-get update
apt-get install sun-java6-jdk sun-java6-plugin
[/shell]
编译安装MySQL(主要是为了php5)
[shell]
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.53.tar.gz/from/http://sunsite.informatik.rwth-aachen.de/mysql/
tar -xzvf mysql-5.1.53.tar.gz
#配置
CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti"
./configure --prefix=/usr/local/mysql --enable-assembler --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-extra-charsets=gb2312,gbk,utf8,latin1 --without-debug --with-charset=utf8 --with-collation=utf8_general_ci --with-pthread --enable-static --enable-thread-safe-client
#编译安装
make
sudo make install
[/shell]
其他配置请参考:CentOS 5.4编译安装MySQL
编译安装php(一定要dev的)
[shell]
sudo apt-get install php5-dev
[/shell]
2、编译安装Thrift
我主要需要同时支持C++和PHP的,能支持Python最好
[shell]
wget
tar -xzvf
./configure
[/shell]
还要单独安装php的支持文件
[shell]
sudo mkdir -p /usr/share/php/Thrift
cd /home/liheyuan/code/thrift-0.5.0/lib/php/src
sudo cp -rf * /usr/share/php5/Thrift/
[/shell]

3、手动编译php的拓展
其实不用拓展也可以用,但是编译拓展的话性能会很好
[shell]
cd ~/code/thrift-0.5.0/lib/php/src/ext/thrift_protocol
phpize
./configure --enable-thrift_protocol
make
sudo make install
[/shell]
还要在php的ini中启用
[shell]
sudo vim /etc/php5/conf.d/thrift_protocol.ini
#写入
extension=thrift_protocol.so
[/shell]
推荐这篇文章:https://wiki.fourkitchens.com/display/PF/Using+Cassandra+with+PHP

补充:不需要php时候的configure
[shell]
./configure --prefix=/usr --without-ruby --without-haskell --without-python --without-perl --without-php --without-php_extension
[/shell]

Leave a Reply

Your email address will not be published. Required fields are marked *