mac m2 安装php8.1 swoole环境
查看可安装版本
brew search php
安装PHP8.1
brew install php@8.1
设置PHP环境变量
编辑.zshrc
vim ~/.zshrc
底下添加上图安装后的环境变量
export PATH=“/opt/homebrew/opt/php@8.1/bin: P A T H " e x p o r t P A T H = " / o p t / h o m e b r e w / o p t / p h p @ 8.1 / s b i n : PATH" export PATH="/opt/homebrew/opt/php@8.1/sbin: PATH"exportPATH="/opt/homebrew/opt/php@8.1/sbin:PATH”
export LDFLAGS=“-L/opt/homebrew/opt/php@8.1/lib”
export CPPFLAGS=“-I/opt/homebrew/opt/php@8.1/include”
添加后执行,使变量立即生效
source ~/.zshrc
验证环境生效
php -v
更新pecl
# 更新源
pecl channel-update https://pecl.php.net/channel.xml
pecl clear-cache
pecl update-channels
用pecl安装swoole
pecl install swoole
php.ini开启扩展
编辑php.ini
vim /opt/homebrew/etc/php/8.1/php.ini
最后面添加
extension=swoole.so
验证swoole安装成功
> php -i | grep swoole
常见异常
fatal error: ‘pcre2.h’ file not found
cp /opt/homebrew/Cellar/pcre2/10.43/include/pcre2.h /opt/homebrew/Cellar/php@8.1/8.1.28/include/php/ext/pcre/pcre2.h
注意安装路径