Centos7下s安装php7.2和swoole扩展

Centos7Yum安装PHP7.2

1、安装源
安装php72w,是需要配置额外的yum源地址的,否则会报错不能找到相关软件包。
php高版本的yum源地址,有两部分,其中一部分是epel-release,另外一部分来自webtatic。如果跳过epel-release的话,安装webtatic的时候,会有错误爆出。
所以,这里需要的命令是:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

当然,您也可以选择下面的这个命令,也是一样的效果。

yum install epel-release -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2、清除历史版本
为了防止centos上面发生php冲突,所以,这个命令还是先执行一下更好些。

yum -y remove php*

3、安装扩展包
事实上,这里面的对应扩展库很多,这里大家一定要注意cli和fpm这两个包,而其它的相关包就看您需要了。

yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel 

还有比较豪华的版本

yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml

4、安装完成以后,启动服务

systemctl enable php-fpm.service
systemctl start php-fpm.service

5、安装成功
通过命令查看是否成功

php -v

swoole安装

1、安装pecl
用pecl安装swoole。默认安装 php7.2 没有pecl

yum install php72w-devel
yum install php72w-pear

2、安装 swoole

pecl install swoole

错误处理
1.C++ preprocessor “/lib/cpp” fails sanity check
没有c++库

yum install glibc-headers
yum install gcc-c++ 

2.fatal error: openssl/ssl.h: No such file or directory

yum install openssl-devel

3.#error “Enable http2 support, require nghttp2 library.”

wget https://github.com/nghttp2/nghttp2/releases/download/v1.34.0/nghttp2-1.34.0.tar.bz2
tar -xjf nghttp2-1.34.0.tar.bz2

如果解压报错
bzip2:无法 exec: 没有那个文件或目录
执行

yum install -y bzip2

cd nghttp2-1.34.0
./configure
make
make install

4.fatal error: hiredis/hiredis.h: No such file or directory

wget https://github.com/redis/hiredis/archive/v0.14.0.tar.gz

 tar xzvf v0.14.0.tar.gz

cd hiredis-0.14.0/

make && make install

执行

vi ~/.bash_profile
[最后加上这句]export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

[退出来]
source ~/.bash_profile

不修改.bash_profile文件,扩展添加会报错

3、修改配置
如何找到php.ini文件

php -i | grep "Loaded Configuration File"

php.ini 中加入
extension=swoole.so

php -m

如果有swoole 扩展就大功告成。

测试:

php -m|grep swoole 

如所示就表示成功安装:

[root@txw etc]# php -m|grep swoole 
swoole
[root@txw etc]#

附加:
我在supervisor 中运行swoole程序,报错
PHP Startup: Unable to load dynamic library ‘swoole.so’ (tried: /usr/lib64/php/modules/swoole.so (libhiredis.so.0.14: cannot open shared object file: No such file or directory), /usr/lib64/php/modules/swoole.so.so (/usr/lib64/php/modules/swoole.so.so: cannot open shared object file: No such file or directory))
困扰了我很久,然后找到解决办法

echo '/usr/local/lib' >>/etc/ld.so.conf 
ldconfig

原文链接:https://www.jianshu.com/p/b211d11b7a95

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章