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?
1条回答 默认 最新
- duanhangjian8149 2016-08-09 23:45关注
Configure 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
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.
Restart your web server or any other PHP related services, e.g.
$ sudo service apache2 restart $ sudo service php5-fpm restart
Install the php-debug package in Atom:
Go to Atom -> Preferences -> Install, search for php-debug and install the package
Configure php-debug in Atom:
Atom -> Preferences -> Packages, search for php-debug and click Settings
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.
Server Port: 9999
Start debugging:
Open your target source file in Atom, e.g. /Users/someuser/Documents/vagrant-mysite/foo.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
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
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
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥50 同步两个不同结果的array中某些属性
- ¥15 悬赏15远程操控解决问题
- ¥15 CST复制的模型无法单独修改参数?
- ¥15 前端页面想做个定时任务,但是使用requestAnimationFrame,setinterval和settimeout都不行
- ¥15 根据以下文字信息,做EA模型图
- ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
- ¥15 vscode程序一直报同样的错,如何解决?
- ¥15 关于使用unity中遇到的问题
- ¥15 开放世界如何写线性关卡的用例(类似原神)
- ¥15 关于并联谐振电磁感应加热