一. 安装护依懒包
1.nghttp2
#wget https://github.com/nghttp2/nghttp2/releases/download/v1.19.0/nghttp2-1.19.0.tar.gz
#./configure
#make && make install
2.hredis
#wget https://github.com/redis/hiredis/archive/v0.13.3.tar.gz
#tar zxvf v0.13.3.tar.gz
#cd hiredis-0.13.3/
#make
#make install
添加环境变量。因程序运行时,会用到libhiredis.so.0.13这个动态库,所以需要把它的路径加到环境变量里
vi ~/.bash_profile #用vi打开当前用户的bash_profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib #在最后一行添加
二. 下载安装swoole
#wget https://codeload.github.com/swoole/swoole-src/tar.gz/v2.0.9
#tar zxvf swoole-src-2.0.9.tar.gz
我已经安装过PHP了,这里是把swoole扩展编译到Php扩展中
#/usr/local/php/bin/phpize
#./configure --enable-sockets --enable-openssl --with-openssl-dir --enable-http2 --enable-async-redis --enable-timewheel --enable-mysqlnd
#make
#make install
说明编译安装成功
三. 配置 php.ini
#/usr/local/php/lib/php.ini
extension=swoole.so # 加到最尾
通过php -m或phpinfo()来查看是否成功加载了swoole,如果没有可能是php.ini的路径不对,可以使用php -i |grep php.ini来定位到php.ini的绝对路径。
四. 重启PHP
#/etc/ini.d/php-fpm restart
验证swoole是否安装正确