CentOS 6上安装grpc扩展
环境及相关软件版本要求
- gcc 4.8+
- php5.6+
- grpc c library
- protoc
- php grpc extension
- git >=1.7.3
centos 6默认的gcc版本是4.7,所以需要编译安装4.8,git也是,需要手动编译安装
系统依赖安装
yum install libtool automake autoconf -y
安装gcc 4.8
查看版本:gcc -v, g++ -v
安装如下:
$ wget http://gcc.skazkaforyou.com/releases/gcc-4.8.2/gcc-4.8.2.tar.gz $ tar -zxvf gcc-4.8.2.tar.gz $ cd gcc-4.8.2 $ ./contrib/download_prerequisites $ ./configure --prefix=/usr --enable-threads=posix --disable-checking --enable-languages=c,c++ --disable-multilib $ make && make install
安装之后会自动覆盖gcc命令。
参考:http://blog.csdn.net/majianfei1023/article/details/46811159http://blog.csdn.net/shine_journey/article/details/62039381
安装git
相关依赖及git安装如下:
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc perl-ExtUtils-MakeMaker -y #还需要安装libiconv依赖 wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz tar -zxvf libiconv-1.14.tar.gz cd libiconv-1.14 ./configure --prefix=/usr/local/libiconv make make install yum remove git #安装git wget https://www.kernel.org/pub/software/scm/git/git-2.1.2.tar.gz tar -zxvf git-2.1.2.tar.gz cd git-2.1.2 make -j 4 configure ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv make -j 4 make install
由于升级了git版本,git clone 的时候报了如下的错误
fatal: unable to access
'https://github.com/open-falcon/falcon-plus.git/'
: SSL connect error
可靠的解决办法:
yum update -y nss curl libcurl
查看版本:git –version
安装grpc扩展
参考官方文档就可以:https://github.com/grpc/grpc/tree/v1.6.x/src/phphttps://grpc.io/docs/quickstart/php.html
下载grpc及安装grpc c library
grpc有不同的版本,如果按照官网去拉就是最新的1.8.x,也可以指定版本, 如下: 依赖安装如下:
#需要安装:pecl,composer,phpunit,php $ sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm $ sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm $ sudo yum install php56w php56w-devel php-pear phpunit gcc zlib-devel #install composer $ curl -sS https://getcomposer.org/installer | php $ sudo mv composer.phar /usr/local/bin/composer #install phpunit $ wget https://phar.phpunit.de/phpunit-old.phar $ chmod +x phpunit-old.phar $ sudo mv phpunit-old.phar /usr/bin/phpunit
安装grpc c 库
git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc #或者指定版本 git clone -b v1.7.x https://github.com/grpc/grpc cd grpc git pull --recurse-submodules && git submodule update --init --recursive make make install
安装grpc扩展
有两种方式,如果想要安装指定的版本,只能编译安装,我整个流程就是为编译安装而写,如果不指定,可能版本很低,可以直接pecl install grpc可以安装,好像这样安装的不可以用,而且centos 6也不支持这样的安装方式。所以还是编译安装吧。
$ cd grpc/src/php/ext/grpc $ phpize $ ./configure #./configure --with-php-config=/usr/local/php/bin/php-config (php-config路径) $ make $ make install
成功之后就会生成grpc.so文件,添加到php.d/grpc.ini中就可以,内容是:extension=grpc.so
产生protoc命令安装
$ cd grpc/third_party/protobuf $ ./autogen.sh && ./configure && make $ sudo make install
需要把proto文件生成php文件
需要安装以下:
cd grpc make grpc_php_plugin
然后根据下面的命令生成
protoc --proto_path=examples/protos \ --php_out=examples/php \ --grpc_out=examples/php \ --plugin=protoc-gen-grpc=bins/opt/grpc_php_plugin \ ./examples/protos/helloworld.proto
grpc c 库make时报错
错误如下:
[MAKE] Building protobuf checking whether to enable maintainer-specific portions of Makefiles... yes configure: error: cannot find install-sh, install.sh, or shtool in "." "./.." "./../.." make: *** [/home/gulfstream/git/grpc/libs/opt/protobuf/libprotobuf.a] Error 1
解决方法:
cd grpc pushd third_party/protobuf ./autogen.sh popd make
参考:https://github.com/grpc/grpc/issues/4387
参考文档: https://github.com/grpc/grpc/tree/master/src/php#generated-code-tests
http://www.grpc.io/docs/quickstart/php.html
http://www.grpc.io/docs/tutorials/basic/php.html
http://www.grpc.io/
https://gist.github.com/stephenturner/e3bc5cfacc2dc67eca8b
https://github.com/grpc/grpc/tree/master/src/php
https://github.com/grpc/grpc/blob/master/src/core/lib/support/env_linux.c
http://doc.oschina.net/grpc?t=58008#quickstart
http://www.jianshu.com/p/fa126a8535a0
http://blog.csdn.net/u012580566/article/details/53515938
http://blog.csdn.net/zimiao815/article/details/51242814
原文链接:CentOS 6上安装grpc扩展,转载请注明来源!