MAC 安装PHP

brew安装php

 

brew search php 使用此命令搜索可用的PHP版本
brew install php@7.4 使用此命令安装指定版本的php
brew install brew-php-switcher 安装php多版本切换工具
brew-php-switcher 7.4 切换PHP版本到7.4(需要brew安装多个版本)

修改PHP环境变量

vim ~/.zshrc
export PATH=/opt/homebrew/opt/php@7.4/bin:$PATH
export PATH=/opt/homebrew/opt/php@7.4/sbin:$PATH
:wq

使环境变量生效

source ~/.zshrc

brew安装PHP扩展

通过brew安装的PHP版本中自带了pecl,可以直接使用

pecl version 查看版本信息
pecl help 可以查看命令帮助
pecl search redis 搜索可以安装的扩展信息
pecl install redis 安装扩展
pecl install http://pecl.php.net/get/redis-4.2.0.tgz 安装指定版本扩展

会提示是否开启igbinary,lzf,zstd三个扩展项,全部yes.(第三个扩展zstd,如果一直出现错误无法安装可以选择no,不安装此扩展)

如果报错Cannot find igbinary.h,则安装igbinary模块

pecl install igbinary
checking for libzstd files in default path... not found
configure: error: Please reinstall the libzstd distribution
ERROR: `/private/tmp/pear/temp/redis/configure --with-php-config=/usr/local/opt/php@7.3.21/bin/php-config --enable-redis-igbinary=yes --enable-redis-lzf=yes --enable-redis-zstd=yes' failed

解决方法:使用brew安装

brew install zstd

通过pecl 安装swoole扩展

pecl install swoole

全程yes

openssl 出现错误

在yes后面添加openssl的路径

yes --with-openssl-dir=/opt/homebrew/Cellar/openssl@1.1/1.1.1k

出现 pcre2.h:No such file or directory  错误

ln -s /opt/homebrew/include/pcre.h /opt/homebrew/Cellar/php@7.4/7.4.16/include/php/ext/pcre/pcre.h

将homebrew/include中的pcre.h 软链接到php目录中

重新执行pecl install swoole 即可安装成功

发表回复

电子邮件地址不会被公开。必填项已用 * 标注