在Ubuntu下编译安装Thrift(支持php和c++)
Thrift是一个开源的RPC框架,由知名SNS社区FaceBook贡献。下面记录了在Ubuntu 10.04下编译安装Thrift的全过程。
1、编译安装依赖
安装Java(除非你不想RPC使用Java)
add-apt-repository "deb http://archive.canonical.com/ lucid partner"
apt-get update
apt-get install sun-java6-jdk sun-java6-plugin
编译安装MySQL(主要是为了php5)
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
编译安装php(一定要dev的)
sudo apt-get install php5-dev
2、编译安装Thrift
我主要需要同时支持C++和PHP的,能支持Python最好
wget
tar -xzvf
./configure
还要单独安装php的支持文件
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/
3、手动编译php的拓展
其实不用拓展也可以用,但是编译拓展的话性能会很好
cd ~/code/thrift-0.5.0/lib/php/src/ext/thrift_protocol
phpize
./configure –enable-thrift_protocol
make
sudo make install
还要在php的ini中启用
sudo vim /etc/php5/conf.d/thrift_protocol.ini
#写入
extension=thrift_protocol.so
补充:不需要php时候的configure
./configure –prefix=/usr –without-ruby –without-haskell –without-python –without-perl –without-php –without-php_extension