首先进入swoole的github下载地址:https://github.com/swoole/swoole-src/releases
如果没有特殊需求,请选择最新版本开始下载(我这里是最新版是v4.4.16):
安装命令
wget https://github.com/swoole/swoole-src/archive/v4.4.16.tar.gz
tar -zvxf v4.4.16.tar.gz
cd swoole-src-4.4.16/
phpize
./configure --with-php-config=/opt/php/bin/php-config --enable-openssl
make && make install
如果此时没有报错的话,那就是安装成功了。
接下来就需要配置php的扩展(php 如何安装本文档不在说明了)
找到 php.ini 文件 根据自己的安装路径来找
在 php.ini 中添加
extension=swoole.so
然后执行
php --ri swoole
如果输出如下 则说明 swoole 安装成功了
swoole
Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.4.16
Built => Jul 14 2020 13:57:59
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.0.2k-fips 26 Jan 2017
pcre => enabled
zlib => 1.2.7
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled
Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
然后 执行
php -m
命令 查看php 扩展是否安装成功