Installation and configuration of PHP code debugging Tools Xdebug in Windows and Linux _php instance

Source: Internet
Author: User
Tags phpinfo
Why do I need debugger?

Many PHP programmers debug using Echo, Print_r (), Var_dump (), printf () and so on, in fact, for developers with a richer development experience these are enough, they can often in the process of program execution, By outputting the value of a particular variable, you can tell whether the program is executing correctly, or even how efficient it may be (some time functions, of course). So why do we need a dedicated debug program to monitor our program's operation? The answer to this question may be left behind to reveal.

Second, what is Xdebug?

Xdebug is an open source PHP program debugger (a debug tool) that can be used to track, debug, and analyze the health of PHP programs.

Iii. installation and configuration of Windows XDebug

1. Download xdebug binary file: http://www.xdebug.org/download.php
Please select the download according to the PHP version, for example:
Copy CodeThe code is as follows: 5.2 Http://www.xdebug.org/files/php_xdebug-2.1.2-5.2-vc6.dll
5.3 Http://www.xdebug.org/files/php_xdebug-2.1.2-5.3-vc6.dll
2. Locate and open the php.ini file
3. If you have configured Zendoptimizer, you need to first mask the Zendoptimizer-related configuration, usually as follows:
Copy CodeThe code is as follows: [Zend]
Zend_extension_manager.optimizer_ts= "Path\zendoptimizer-3.3.0\lib\optimizer-3.3.0″
Zend_extension_ts= "Path\zendoptimizer-3.3.0\lib\zendextensionmanager.dll"
Delete it or comment it out with a semicolon, such as instead:
Copy CodeThe code is as follows:; [Zend]
; zend_extension_manager.optimizer_ts= "Path\zendoptimizer-3.3.0\lib\optimizer-3.3.0″
; zend_extension_ts= "Path\zendoptimizer-3.3.0\lib\zendextensionmanager.dll"
4. Join the XDebug configuration. Refer to the following:
Copy CodeThe code is as follows: [Xdebug]
Zend_extension_ts= "Path/xdebug/php_xdebug-2.1.2-5.2-vc6.dll"
Xdebug.auto_trace=on
Xdebug.trace_output_dir= "Path\xdebug"
Xdebug.profiler_enable=on
Xdebug.profiler_output_dir= "Path\xdebug"
Xdebug.collect_params=on
Xdebug.collect_return=on
Xdebug.remote_enable=on
Xdebug.remote_handler=dbgp
Xdebug.remote_host=localhost
xdebug.remote_port=9000

Description:
The location above "path" needs to be modified to your own local path.
Parameter explanation: The
copy Code code is as follows:
zend_extension_ts= "C:/webserver/php5/ext/php_xdebug.dll"
; Load the Xdebug module. Here can not be loaded with Extension=php_xdebug.dll way, it must be loaded in a zend way, or after installation, Phpinfo is not shown xdebug this item.
Xdebug.auto_trace=on;
; automatically turn on the "monitor function call process" mode. This function can output the monitoring information of a function call as a file in the directory you specify. The default value for this configuration item is off.
Xdebug.collect_params=on;
to open the function that collects the function parameters. The parameter values of the function call are included in the monitoring information for the Function procedure call. The default value for this configuration item is off.
Xdebug.collect_return=on
; Opens the function that collects the function return value. The return value of the function is included in the monitoring information of the Function procedure call. The default value for this configuration item is off.
Xdebug.trace_output_dir=
; Sets the path to the output file of the function invocation monitoring information.
Xdebug.profiler_enable=on
; open the Performance Monitor.
Xdebug.profiler_output_dir=
; Sets the path of the performance monitoring information output file.

There are some more specific parameter settings, see: http://www.xdebug.org/docs-settings.php
5. Restart the Web server, such as Apache or IIS
6. Look at the output of the phpinfo, and if you see the XDebug option, the configuration is successful.
7. Debug information file view.
Running a PHP program locally will generate some debugging information in the directory you set up, mainly including:
A. Function call process monitoring information file, file name format: TRACE.XXXXXX.XT. The file can be viewed directly, containing information such as the time the function was run, the parameter value of the function call, the return value, the file and location. The content format is relatively straightforward.
B. Performance monitoring file, file name format: cachegrind.out.xxxxxxxx.
The file can also be viewed directly, but the information format is not easily understood by humans, and we can install the Wincachegrind software to read it in a formatted manner. Download the installation method reference as follows:
Download: http://sourceforge.net/projects/wincachegrind/
Install and run after download, then click Tools->options, set working folder (Xdebug.profiler_output_dir value in php.ini)
This allows for a more intuitive view of the performance monitoring file information.

Iv. installation and configuration of Linux under XDebug

Linux can download the source code to compile the installation, the method reference is as follows.
1. Download the corresponding PHP version of the source code source:http://www.xdebug.org/download.php
For example xdebug-2.1.2.tgz version: Http://www.xdebug.org/files/xdebug-2.1.2.tgz
2. Compiling the installation
Copy the Code code as follows: Tar-xvzf xdebug-2.1.2.tgz
CD xdebug-2.1.2
./configure
Make
Make install
If there is an error phpize does not have this command, then install it:
Copy the Code code as follows: sudo apt-get install Php5-dev
3. Move the xdebug.so file below the PHP5
Copy the Code Code as follows: CP modules/xdebug.so/usr/lib/php5/
4. Edit the php.ini and add the following lines:
Copy the Code code as follows: [Xdebug]
zend_extension=/usr/lib/php5/xdebug.so
Xdebug.profiler_enable=on
Xdebug.trace_output_dir= ". /xdebug "
Xdebug.profiler_output_dir= ". /xdebug "

5. Restart Apache to test if the installation was successful

If you see Xdebug in the output content, the installation configuration is successful.

  • Related Article

    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.