1、更新一下源
yum update
2、 安裝pecl(默認(rèn)安裝 php7.2 沒(méi)有pecl,如果已經(jīng)安裝可忽略)
yum install php72w-devel
yum install php72w-pear
3、安裝 swoole
pecl install swoole
3.1補(bǔ)充: 關(guān)于 Swoole 安裝配置選項(xiàng):(特別注意:如果有些擴(kuò)展沒(méi)安裝,yes之后后面會(huì)報(bào)錯(cuò))
// 是否啟用 Debug 跟蹤調(diào)試 // 啟用后,會(huì)在命令行中輸出 Debug 跟蹤 log,我一般禁用此項(xiàng)。 enable debug/trace log support? [no] : no // 是否啟用 PHP Sockets 支持 // 如果你需要用 PHP 編寫(xiě) Sockets 服務(wù),可以啟用此項(xiàng)。 enable sockets supports? [no] : yes // 是否啟用 OpenSSL 支持 // 是否啟用 SSL 加密,如果你是通過(guò) Swoole 提供對(duì)外的 HTTPS 服務(wù),則需要啟用此項(xiàng)。 // 我的 Mac 是本地開(kāi)發(fā)用,所以不啟用。 enable openssl support? [no] : no // 是否啟用 HTTP2 支持 // 了解 HTTP2 新特性 https://zh.wikipedia.org/wiki/HTTP/2 enable http2 support? [no] : yes // 是否啟用異步 Redis 支持 // Swoole 實(shí)現(xiàn)了一套支持異步的 Redis 服務(wù)端框架 // https://wiki.swoole.com/wiki/page/p-redis_server.html enable async-redis support? [no] : yes // 是否啟用 MySQL 原生支持 enable mysqlnd support? [no] : yes // 是否啟用 PgSQL 協(xié)程客戶(hù)端支持 enable postgresql coroutine client support? [no] : yes
-------------------出現(xiàn)下面的提示,很高興的告訴你,你成功了-------------------------------
Installing '/usr/lib64/php/modules/swoole.so'
Installing '/usr/include/php/ext/swoole/config.h'
install ok: channel://pecl.php.net/swoole-4.3.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=swoole.so" to php.ini
4、 修改配置
vi /etc/php.ini 中加入
extension=swoole.so
5、重啟
service php-fpm restart
service httpd restart
6、查看
php -m 或者 phpinfo() 查看是否有swoole
備注(安裝過(guò)程中有可能會(huì)出現(xiàn)下面錯(cuò)誤)
1、問(wèn)題:PHP Startup: Unable to load dynamic library 'swoole.so' (tried: /usr/lib64/php/modules/swoole.so (/usr/lib64/php/modules/swoole.so: 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)) in Unknown on line 0
解決方法:把3.1補(bǔ)充說(shuō)明內(nèi)的全部擴(kuò)展全部安裝一遍
2、問(wèn)題,如果使用php -m或者 phpinfo()查看不到swoole
解決方法:(確定安裝和配置都沒(méi)有問(wèn)題)
1、如果使用兩種方法都無(wú)法查看swoole,那么請(qǐng)執(zhí)行第五步重啟
2、如果使用php -m無(wú)法查看swoole,請(qǐng)使用命令service php-fpm restart重啟
3、如果使用phpinfo()無(wú)法查看swoole,請(qǐng)使用命令service httpd restart重啟
3、 問(wèn)題 C++ preprocessor “/lib/cpp” fails sanity check
解決方法:沒(méi)有c++庫(kù)
yum install glibc-headers yum install gcc gcc-c++ gcc-g77
4、問(wèn)題:fatal error: openssl/ssl.h: No such file or directory
解決方法:沒(méi)有
openssl/ssl此類(lèi)文件或目錄yum install openssl-devel
5、問(wèn)題: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
6、問(wèn)題PHP Warning: Module 'swoole' already loaded in Unknown on line 0
解決方法:
在修改配置時(shí)extension=swoole.so別放在最后,最好放在extension=sockets.so后面,