Vim+xdebug Debugging PHP

Source: Internet
Author: User

1 Installing the PHP debugging environment

After installing Php-devel, there will be phpize and php-config scripts.

Yum installphp-devel.x86_64

2 Installing Xdebug2.1 Installation

Installing with Yum may fail with PECL installation success.

#yum installphp-pecl-xdebug.x86_64

Pecl Installxdebug

2.2 Modify Permissions

Assigning shared libraries xdebug.so Execute permissions

chmod +x/usr/lib64/php/modules/xdebug.so

2.3 Modifying the PHP configuration

To create a new profile Xdebug.ini (or append directly to php.ini) under/ETC/PHP.D, add the following:

===============================================================================

[Xdebug]
Xdebug.defalut_enable=on
Zend_extension =/home/rong/php-5.5.16/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
zend_debugger.allow_hosts=127.0.0.1
Zend_debugger.expose_remotely=always
Zend_debugger.httpd_uid=-1
Xdebug.auto_trace = On
Xdebug.auto_profile = On
Xdebug.collect_params = On
Xdebug.collect_return = On
Xdebug.profiler_enable = On
Xdebug.trace_output_dir = "/tmp"
Xdebug.profiler_output_dir = "/tmp"
Xdebug.dump.GET = *
Xdebug.dump.POST = *
Xdebug.dump.COOKIE = *
Xdebug.dump.SESSION = *
Xdebug.var_display_max_data = 4056
Xdebug.var_display_max_depth = 5
Xdebug.remote_enable=on
Xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9010
Xdebug.remote_autostart=1

===============================================================================

Red is the key content, configure the location of the xdebug.so, and enable Xdebug to open the remote debugging mode. Remote_port a must be consistent with the VIM configuration or IDE configuration that will be mentioned later.

2.4 Verifying that the installation was successful

Visit the test page http://localhost/test.php to see if Xdebug is included in the output of the Phpinfo () function.

3 Installing the VIM Debug Plugin 3.1 download installation

VIM supports Xdebug for plugins in this:

http://www.vim.org/scripts/script.php?script_id=1929

After decompression, copy the plugin folder in the plugin to xxx/vim/plugins/.

Cp–r debugger/* xxx/vim/plugins/

3.2 Modifying the default port

Under/home/user, create a new. vimrc file, and join the configuration as follows:

Let G:debuggerport = 9010

Note: Be consistent with the port configuration in Xdebug.ini.

4 Debugging examples

Take/export/data/discuz/test.php as an example (/export/data/discuz is my discuz! x root directory).

test.php content is as follows:

===============================================================================

<?php

Phpinfo ();

$name = "Cdai";

Print ("Hello {$name}");

?>

===============================================================================

Open test.php with vim and switch to print ("Hello {$name}"); This line, input : Bp command plus breakpoint.

Press F5 to start listening, which requires a browser to access the test.php page within five seconds.

Http://localhost/test.php?XDEBUG_SESSION_START=1

Note: Be sure to add the xdebug_session_start=1 parameter to the URL to turn on debugging.

When you enter a URL, the call stops at the breakpoint line. As follows:

Attached: Debugging basic operations

[Function Keys]

<F1>

Resize

resizing windows

<F2>

Step Into

<F3>

Step Over

<F4>

Step out

<F5>

Run

<F6>

Quit debugging

<F11>

Get all context

Get all variable contents

<F12>

Get property at cursor

Gets the current cursor variable

[Normal Mode]

E

Eval

[Command Mode]

: Bp

Toggle Breakpoint

: Up

Stack up

:D N

Stack down

Vim+xdebug Debugging PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.