1、官网下载最新扩展
wget http://pear.php.net/go-pear.phar
说明:如果提醒你需要更新,则更新命令
2、开始安装
sudo pecl install swoole
tips:如果提示没有pecl命令,则通过brew install pecl
brew install pecl
3、配置
Configuring for:
PHP Api Version: 20190902
Zend Module Api No: 20190902
Zend Extension Api No: 320190902
enable sockets supports? [no] : yes
enable openssl support? [no] : yes --with-openssl-dir=/usr/local/Cellar/openssl@1.1/1.1.1i/
enable http2 support? [no] : yes
enable mysqlnd support? [no] : yes
每个配置项的意义:自行google,参考链接
tips:特别提醒的是:openssl一定要根据自身环境来配置正确的路径,鄙人就是在这个问题上费了好大劲,因为没有配置准确路劲,导致错误如下:Enable openssl support, require openssl library
4、安装成功
Build process completed successfully
Installing '/usr/local/Cellar/php@7.4/7.4.13_1/include/php/ext/swoole/config.h'
Installing '/usr/local/Cellar/php@7.4/7.4.13_1/pecl/20190902/swoole.so'
install ok: channel://pecl.php.net/swoole-4.5.10
Extension swoole enabled in php.ini
通过 php -v
显示
5、配置php.ini文件
sudo vi /usr/local/etc/php/7.4/php.ini
增加swoole扩展
extension="swoole.so"
6、重启apache
sudo apachectl restart
至此,mac上brew安装swoole版本成功;
安装过程中可能出现的错误:
1 fatal error: ‘openssl/ssl.h‘ file not found
解决方法1:cp -R /usr/local/opt/openssl/include/openssl /usr/local/include
解决方法2:ln -s /usr/local/opt/openssl/include/openssl /usr/local/include/openssl
原因:一般用brew安装的软件,都会把需要include的文件自动放到/usr/local/include里的,但是不知为什么安装openssl的时候没有放到那里,所以要自己拷过去,其实最好的方法是做一个链接,即用解决方法2!
详情查看,网友提供方案:[swoole安装问题集锦(https://www.cnblogs.com/xiaobaiskill/p/11062024.html)