Linux 安装 Swoole扩展
1. 查看 PHP 配置信息
[root@VM-4-10-centos ~]# whereis php
PHP 的安装路径是 /usr/bin/php
[root@VM-4-10-centos ~]# php --ini
php.ini 的路径是 /www/server/php/74/etc/php.ini
2. 安装 Swoole
2.1 下载
Swoole 源码地址
https://github.com/swoole/swoole-src/releases
https://pecl.php.net/package/swoole
https://gitee.com/swoole/swoole/tags
我这用的下载链接是 https://pecl.php.net/get/swoole-4.8.2.tgz
[root@VM-4-10-centos server]# wget https://pecl.php.net/get/swoole-4.8.2.tgz
如果出现了一下的问题则需要在命令后添加 –no-check-certificate
[root@VM-4-10-centos server]# wget https://pecl.php.net/get/swoole-4.8.2.tgz --no-check-certificate
这样就下载成功了
2.2 解压
[root@VM-4-10-centos server]# tar zxvf swoole-4.8.2.tgz
2.3 安装
[root@VM-4-10-centos swoole-4.8.2]#cd swoole-4.8.2 && phpize && ./configure --with-php-config=/www/server/php/74/bin/php-config && make && sudo make install
其中 /www/server/php/74/bin/php-config 这个路径是 php.ini 安装文件那去找
这样是安装完成了
3. PHP 配置 Swoole 扩展
3.1 编辑 php.ini 文件
编辑 php.ini 文件 在最后一行添加 extension=swoole.so (注: vi编辑页面时 按 Shift+G 可直接跳到最后一行)
添加以上内容保存退出即可
3.2 重启 PHP 服务
[root@VM-4-10-centos swoole-4.8.2]# service php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service
Job for php-fpm-74.service failed because the control process exited with error code.
See "systemctl status php-fpm-74.service" and "journalctl -xe" for details.
输入 php -m 查看一下
[root@VM-4-10-centos swoole-4.8.2]# php -m
这样就完成了