Wednesday, October 12, 2011

Xdebug Installation Tutorial


Xdebug is one of the best debuggers for PHP. It is completely free and continously maintained by its developer. Most of the PHP development environments have the posiblility to connect to a server side environment running PHP with Xdebug. Ability to debug can dramatically reduce the time to market for a PHP application.

In order to install xdebug, first you need to gather detailed information regarding your environment structure. You need to know the exact versions for all the environment modules (PHP, Apache, etc).

After you are done with this, please proceed:

Download the package. There are many versions available, you need to make sure that you download the appropriate one. A note: xdebug must match your php installation. Let's say we run PHP version 5.2, we download xdebug version 5.2VC6.

Double check the file downloaded. Must contain the php version in the name. Our currently downloaded file is php_xdebug-2.0.2-5.2.5.dll

Copy the file in the PHP extension folder. The folder usually is under the PHP main installation folder and it is called ext.

Install the file under PHP as follows:

Open the php.ini file for editing. Double check it is the actual ini file that gets loaded when php runs.

Ensure there is no entry with the key zend_extension_ts. Our installation will actually insert a line starting with this key and it is important they don't collide.

Copy the following lines:



[xdebug]

xdebug.remote_enable=1

xdebug.remote_host="localhost"

xdebug.remote_port=9000

xdebug.remote_handler="dbgp"

zend_extension_ts="c:/environment/php5.2.8/ext/php_xdebug-2.0.2-5.2.5.dll"

Please note that the zend_extension_ts file contains the full path to the downloaded xdebug dll file. Also, 9000 is the port used to connect to the debugging environment (the environment listens on this port). Make sure the port is not currently in use by other process, otherwise it will not work.

At the end, please restart apache and display again the page containing the phpinfo(); call. Carefully look at the displayed result, and you should see mentioned that xdebug is currently installed. There will be an entry called xdebug and all the properties for this module are listed underneath. The port should be listed there as well and must match the one you just configured. If you don't see anything with xdebug, please look at the Apache error log and surely you will see something there - either the dll version is the wrong one, or maybe its name was misspelled and because of that the system could not load it.

The latest test is to install a sample php file under the main htdocs folder, open it in a development environment, connect the development environment to xdebug (make sure the port on the xdebug client side matches the one that was configured as above) try to set a breakpoint and then run the program. Once you see it stops at the break point, try to see if the variables are communicated and you can inspect them.

Once this done, you are ready to run your applications in debug mode and dramatically improve your performance.




A number of tutorials, free of charge, can be found at http://proghowto.com/


No comments:

Post a Comment