PHP mac下 xampp + vscode + xdebug 环境配置
作者:Seiya
时间:2019年05月22日
前言
本人是PHP初学者,因工作需要,了解PHP代码故学习搭建环境,这里记录一下。
XAMPP安装和配置
需要注意的是,在mac中的xampp有两个版本,一个是正常版本,一个是虚拟机版本。第一次安装时,由于不了解,所以安装成了虚拟机版本,导致在进行根目录配置时,无法生效,还有各种各样的使用困难,建议初学者还是选择正常版本安装。
项目根目录配置
xdebug安装
判断xdebug需要的版本
首先通过PHP内置的
phpinfo()
函数获取到系统内部的PHP版本信息;然后右键“获取源代码”,复制全部内容,打开上面
xdebug版本检查
的连接,并复制内容粘贴到输入框内,点击下面的按钮;完成上述步骤后,它会自动向你推荐合适的xdebug版本,并提示了安装步骤,按照步骤进行安装即可;
xdebug安装错误一:Cannot find autoconf
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
解决方案:
brew install autoconf
xdebug安装错误二:autom4te: need GNU m4 1.4 or later: /usr/bin/m4
autom4te: need GNU m4 1.4 or later: /usr/bin/m4
解决方案:
mv /Applications/MAMP/Library/bin/m4 /Applications/MAMP/Library/bin/m4_backup
ln -s /usr/local/opt/m4/bin/m4 /Applications/MAMP/Library/bin/m4
phpize
unlink /Applications/MAMP/Library/bin/m4
mv /Applications/MAMP/Library/bin/m4_backup /Applications/MAMP/Library/bin/m4
xdebug安装错误三:error: C compiler cannot create executables
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... no
configure: error: in `/Users/Fan/Desktop/xdebug-2.7.2':
configure: error: C compiler cannot create executables
See `config.log' for more details
解决方案:
xcode-select --install
xdebug安装错误四:
/Users/Fan/Desktop/xdebug-2.7.2/xdebug.c:25:10: fatal error: 'php.h' file not found
/usr下没有include 目录,这个目录就是 sudo 也无法创建,会报权限不够,由于这个目录的不存在,所以phpize命令也是无法正常执行。找了很多方法尝试无法解决,最终解决方案如下:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
修改php.ini文件:
在php.ini文件中新增xdebug配置:
[xdebug]
zend_extension=/Applications/XAMPP/xamppfiles/etc/xdebug.so ;文件路径
xdebug.remote_port=9001
xdebug.remote_enable = 1 ;开启生成报告文件
xdebug.remote_autostart=on ;开启远程调试自动启动
xdebug.remote_log="/var/log/xdebug.log"
xdebug.remote_host = "localhost"
xdebug.remote_handler="dbgp" ;用于zend studio远程调试的应用层通信协议
xdebug.show_local_vars = 1 ;显示局部变量
vscode配置xdebug插件
搜索php debug 安装重启,选择调试界面进行配置,启动Listen for XDebug进行监听,注意监听端口需要和xdebug设置的端口保持一致。