Centos7+php7.2+swoole

Centos7Yum安裝PHP7.2

1、安裝源
安裝php72w,是需要配置額外的yum源地址的,否則會(huì)報(bào)錯(cuò)不能找到相關(guān)軟件包。
php高版本的yum源地址,有兩部分,其中一部分是epel-release,另外一部分來自webtatic。如果跳過epel-release的話,安裝webtatic的時(shí)候,會(huì)有錯(cuò)誤爆出。
所以,這里需要的命令是:

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

當(dāng)然,您也可以選擇下面的這個(gè)命令,也是一樣的效果。

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

2、清除歷史版本
為了防止centos上面發(fā)生php沖突,所以,這個(gè)命令還是先執(zhí)行一下更好些。

yum -y remove php*

3、安裝擴(kuò)展包
事實(shí)上,這里面的對應(yīng)擴(kuò)展庫很多,這里大家一定要注意cli和fpm這兩個(gè)包,而其它的相關(guān)包就看您需要了。

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、安裝完成以后,啟動(dòng)服務(wù)

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

5、安裝成功
通過命令查看是否成功

php -v

swoole安裝

1、安裝pecl
用pecl安裝swoole。默認(rèn)安裝 php7.2 沒有pecl

yum install php72w-devel
yum install php72w-pear

2、安裝 swoole

pecl install swoole

錯(cuò)誤處理
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

如果解壓報(bào)錯(cuò)
bzip2:無法 exec: 沒有那個(gè)文件或目錄
執(zhí)行

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

執(zhí)行

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

[退出來]
source ~/.bash_profile

不修改.bash_profile文件,擴(kuò)展添加會(huì)報(bào)錯(cuò)

3、修改配置
php.ini 中加入
extension=swoole.so

php -m

如果有swoole 擴(kuò)展就大功告成。

如何找到php.ini文件

php -i | grep "Loaded Configuration File"

附加:
我在supervisor 中運(yùn)行swoole程序,報(bào)錯(cuò)
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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容