由于mac系统升级到了最新版本,在配置php扩展包时遇到了很多问题,现在将几个关键的步骤记录如下:
- 不要用mac自带的php(自带php不能删除!!),因为10.15的系统做了一些修改并增加了某些目录的写入权限,导致配置过程有很多坑,首先要做的是使用brew自行安装php
- 安装xcode
xcode-select --install # 安装 Xcode Command Line Tools
- 切换brew源为国内源
cd "$(brew --repo)" git remote set-url origin https://mirrors.ustc.edu.cn/brew.git # 替换brew.git: cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git # 替换homebrew-core.git: echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> /etc/profile
- 后续在使用brew命令时可能会报一个error,并不影响使用,按照弹出的提示操作就能解决
- 安装php
brew install php
,安装完成后切换系统php为自定义php:brew link php
- 查看php版本和配置文件位置
版本:php -v
配置文件位置:php -i | grep -i "ini"
- 安装xcode
- 安装xdebug和redis扩展
安装Xdebug:pecl install xdebug
安装Redis:pecl install redis
安装完成后会自动在php配置文件中插入一行配置,无需手动增加 - 重启php服务,查看安装结果
brew services restart php
php -v
输出结果:PHP 8.0.0 (cli) (built: Nov 30 2020 13:47:29) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies
- 配置phpstrom xdebug
- 在php.ini配置文件最后插入
其中extension和zend_extension两个配置是之前自动生成的,[]中的内容同样代表注释[redis] extension="redis.so" [xdebug] zend_extension="xdebug.so" xdebug.mode=debug xdebug.client_host=localhost xdebug.client_port=9003
- 在phpstrom中配置cli interpreter为自定义的php
如果1中没有自行安装的php,则需要在2处添加 - 配置xdebug端口和php.ini中的配置一致
- phpstrom中打断点,调试成功