1. 程式人生 > >Centos7 安裝php7.2 和pecl,swoole

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