使用Vagrant时在Atom中调试PHP [英] Debug PHP in Atom While Using Vagrant

查看:63
本文介绍了使用Vagrant时在Atom中调试PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PHP开发环境正在VirtualBox VM上运行,并通过vagrant进行了配置.如何在主机上的Atom中使用php-debug调试运行在其中一台VM上的PHP脚本?

My PHP dev environment is running on a VirtualBox VM and is provisioned via vagrant. How can I use php-debug in Atom on my host machine to debug PHP scripts running on one of my VMs?

推荐答案

配置xdebug:

在虚拟机上打开php.ini文件,查找xdebug设置,并确保您具有以下值:

Open your php.ini file on your VM and look for the xdebug settings and make sure that you have the following values:

xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_mode=req
xdebug.remote_log=/tmp/xdebug.log
xdebug.remote_host=10.0.2.2
xdebug.remote_port=9999

注意:您可能有多个php.ini文件,例如一个用于cli,fpm等.如果要这样做,则需要确保您要使用调试器的所有环境都具有上面的xdebug设置,例如我必须修改/etc/php5/cli/php.ini才能在命令行上使用调试器,而必须修改/etc/php5/fpm/php.ini以便在使用apache运行PHP脚本时使用调试器.

Note: you may have multiple php.ini files, e.g. one for cli, fpm, etc… If you do, you’ll need to make sure that you have the xdebug settings above for all environments where you want to use the debugger, e.g. I had to modify /etc/php5/cli/php.ini to use the debugger on the command line and /etc/php5/fpm/php.ini to use the debugger while running PHP scripts with apache.

重新启动您的Web服务器或任何其他与PHP相关的服务,例如

Restart your web server or any other PHP related services, e.g.

$ sudo service apache2 restart
$ sudo service php5-fpm restart

在Atom中安装php-debug软件包:

转到Atom->首选项->安装,搜索php-debug并安装软件包

Go to Atom -> Preferences -> Install, search for php-debug and install the package

在Atom中配置php-debug:

  • Atom->首选项->软件包,搜索php-debug并单击 设置

  • Atom -> Preferences -> Packages, search for php-debug and click Settings

remote; local 形式设置PathMap.路径图 将来宾/远程路径转换为本地/主机路径.假设 您正在调试 foo.php 并可以在您的VM上找到它 在/var/www/mysite/foo.php 上,并在主机箱上 /Users/someuser/Documents/vagrant-mysite/foo.php .您的路径图 配置将是 /var/www/mysite;/Users/someuser/Documents/vagrant-mysite .

Set the PathMaps in the form remote;local. The PathMaps translate the guest/remote path to the local/host path. Let’s assume that you are debugging foo.php and that it can be found on your VM at /var/www/mysite/foo.php and on your host box at /Users/someuser/Documents/vagrant-mysite/foo.php. Your PathMaps config would then be /var/www/mysite;/Users/someuser/Documents/vagrant-mysite.

服务器端口:9999

Server Port: 9999

开始调试:

  • 在Atom中打开目标源文件,例如 /Users/someuser/Documents/vagrant-mysite/foo.php

  • Open your target source file in Atom, e.g. /Users/someuser/Documents/vagrant-mysite/foo.php

在Atom屏幕的左下角,单击"PHP调试"按钮

In the bottom left corner of your Atom screen, click the "PHP Debug" button

通过立即在目标代码行的左侧单击来设置断点

Set a breakpoint by clicking immediately left of your target line of code

在浏览器中访问foo,例如 http://example.com/foo.php ,这将导致代码在Atom和您应该能够继续调试

Visit foo in the browser, e.g. http://example.com/foo.php and this should cause the code to pause in Atom and you should be able to continue debugging

如果您为PHP命令行设置配置了php.ini文件,则还应该能够仅通过在来宾计算机上运行脚本来进行调试,例如php /var/www/mysite/foo.php

If you configured the php.ini file for your PHP command line settings, you should also be able to debug just by running the script on the guest machine, e.g. php /var/www/mysite/foo.php

这篇关于使用Vagrant时在Atom中调试PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆