macOS: apache配置不同版本的php

macOS Big Sur自带php版本是7.3,安装php7.4并配置apache到该版本

使用brew安装php7.4
brew install php@7.4
brew link php@7.4 --force
根据提示执行如下命令
echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> /Users/username/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> /Users/username/.bash_profile
export LDFLAGS="-L/usr/local/opt/php@7.4/lib"
export CPPFLAGS="-I/usr/local/opt/php@7.4/include"
使用pecl安装php扩展
pecl install zip

修改/etc/apache2/httpd.conf
#LoadModule php7_module libexec/apache2/libphp7.so
LoadModule php7_module /usr/local/opt/php@7.4/lib/httpd/modules/libphp7.so
重启apache
sudo apachectl restart

点赞