Home  >  Article  >  php教程  >  PHP的学习--在sublime中使用XDebug(Ubuntu)

PHP的学习--在sublime中使用XDebug(Ubuntu)

WBOY
WBOYOriginal
2016-06-13 09:27:361024browse

PHP的学习--在sublime中使用XDebug(Ubuntu)

说起来惭愧,自从开始使用Sublime Text之后,再也没有debug过PHP的代码,最近把debug的环境搭建了一下,在这里记录一下。

 

安装XDebug

 

sudo apt-get install php5-xdebug

编辑xdebug.ini文件,添加如下配置

 

xdebug.remote_enable=1

xdebug.remote_handler=dbgp

xdebug.remote_host=127.0.0.1

xdebug.remote_port=9000

xdebug.remote_log="/var/log/xdebug/xdebug.log"

重启nginx

 

sudo /etc/init.d/nginx restart

然后在Sublime Text使用package control安装xdebug client,用ctrl+shift+p调出搜索框,输入Package Control: 选中其中的Package Control: Install Package,输入Xdebug client,找到xdebug client,安装,安装完成后要重启Sublime。其操作如下:

 

 

 

 

 

要调试某一个项目,首先得把这个项目在sublime下保存成一个project。

 

sublime->project->save project as ...

接下来配置项目

 

sublime->project->edit poject

配置文件类似以下内容:

 

复制代码

{

    "folders":

    [

        {

            "follow_symlinks": true,

            "path": "."

        }

    ],

    "settings": {

        "xdebug": {

             "url": "http://my.local.website/",

        }

    }

}

复制代码

再在chrome中安装Chrome Xdebug Helper扩展。在下载和安装Chrome扩展后,你必须重新启动浏览器。重新启动后,你将看到在Chrome的地址栏的新图标:

 

 

 

点击它,将启用/禁用调试。但是,我们首先需要调整扩展中使用 Sublime Text 的会话密钥。

 

在Chrome中Tools > Extensions

 

打开Xdebug helper options:

 

 

 

开启调试方式也比较简单,在想要加断点的地方右键

 

xdebug->Add/Remove breakpoint

这样项目在运行到本行的时候就会停止下来

 

然后开始调试,在菜单栏选择

 

tools->xdebug->start debugging(launch browser)

sublime会自动打开浏览器,进入配置时写的网站链接,进行调试。

 

调试中所用的功能可以在调试文件中右键查看之。

 

快捷键说明如下

 

Start/Stop debugging session

Start Debugging - Ctrl+Shift+F9 or ⌘+Shift+F9

Start Debugging (Launch Browser)

Restart Session

Stop Debugging - Ctrl+Shift+F10 or ⌘+Shift+F10

Stop Debugging (Launch Browser)

Stop Debugging (Close Windows)

Breakpoints

Add/Remove Breakpoint - Ctrl+F8 or ⌘+F8

Set Conditional Breakpoint - Shift+F8

Clear Breakpoints

Clear All Breakpoints

Watch expressions

Set Watch Expression

Edit Watch Expression

Remove Watch Expression

Clear Watch Expressions

Session commands

Evaluate

Execute

Status

Continuation commands

Run - Ctrl+Shift+F5 or ⌘+Shift+F5

Run To Line

Step Over - Ctrl+Shift+F6 or ⌘+Shift+F6

Step Into - Ctrl+Shift+F7 or ⌘+Shift+F7

Step Out - Ctrl+Shift+F8 or ⌘+Shift+F8

Stop

Detach

Other

Restore Layout / Close Windows - Ctrl+Shift+F11 or ⌘+Shift+F11

Settings - Default

Settings - User

问题无法跟踪断点

这可能是xdebug端口被占用,按Ctrl+`或者菜单栏View->show Console查看错误信息,有可能是xdebug端口已经被占用的缘故。

 

在sublime xdebug中关闭调试,或者重启sublime可以解决这个问题,如果还不行,可以修改端口号,如xdebug.ini中的端口号修改为为1000,在perferences->package settings->xdebug->setting-user文件中加入如下内容:

 

{

    "port": 10000

}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn