Centos7 安装php7.2 和pecl,swoole

Centos7 yum源没有PHP7的安装包,贼不方便。。。

Step 1 :换源

yum install epel-release

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

不安装epel有可能会报错。

Step 2: 安装PHP7.2

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

Step 3: 安装pecl

yum install php72w-devel
yum install php72w-pear

不能偷懒,少写72w,用php-pear
这里可能会报错:
错误:php72w-common conflicts with php-common-5.4.16-45.el7.x86_64

Step 4:安装 swoole

pecl install swoole

错误处理

  1. C++ preprocessor “/lib/cpp” fails sanity check
    没有c++库
yum install glibc-headers
yum install gcc-c++ 
  1. fatal error: openssl/ssl.h: No such file or directory
yum install openssl-devel
  1. #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
  1. 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文件,扩展添加会报错

Step 5:修改配置

php.ini 中加入
extension=swoole.so

执行

php -m

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

附加:

我在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

猜你喜欢

转载自blog.csdn.net/zeroking_vip/article/details/83180346