1. 准备依赖(必须)
bash
brew install php autoconf automake libtool pcre openssl
2. 下载 swoole 源码(手动下稳定版)
bash
cd ~/Downloads
# 下载 6.2.0(你刚才失败的版本,也可以换 5.1.2 更稳)
wget https://pecl.php.net/get/swoole-6.2.0.tgz
# 解压
tar -zxvf swoole-6.2.0.tgz
cd swoole-6.2.0
3. 编译(用你 brew 的 php)
bash
# 用 brew 的 phpize(关键,别用系统的)
/usr/local/bin/phpize
# 配置(指定 brew 的 php-config 和 openssl)
./configure \
--with-php-config=/opt/homebrew/opt/php@8.4/bin/php-config \
--with-openssl=/opt/homebrew/opt/openssl \
--with-pcre2-dir=/opt/homebrew/opt/pcre2 \
CFLAGS="-I/opt/homebrew/include" \
CPPFLAGS="-I/opt/homebrew/include" \
LDFLAGS="-L/opt/homebrew/lib"
# 编译安装(以下两行整个复制执行)
make -j$(sysctl -n hw.ncpu)
sudo make install
4、启用扩展
标题找到你的 php.ini
bash
php --ini
#编辑 php.ini(路径替换成你自己的)
bash
vim /usr/local/etc/php/8.4/php.ini
添加:
dart
extension=swoole.so
swoole.use_shortname=Off
5、重启终端,验证:
bash
php -m | grep swoole
输出swoole表示扩展安装成功
dart
yang@MacBook-Pro swoole-6.2.0 % php -m | grep swoole
swoole
yang@MacBook-Pro swoole-6.2.0 %