XDebug: a PHP Debugger

guitarchanceΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 5 χρόνια και 1 μήνα)

254 εμφανίσεις

Debugging PHP scripts with Xdebug and Netbeans


Overview


Debugging is the process of finding and removing bugs, or defects in a computer program of a piece of
software. This is often a complex problem when there are tightly coupled subsystems. Techniques

include logging, profiling, data collection, analysis and scheduling. Debugging is made easier by
employing the use of “debuggers.” These typically include a user interface of some kind that allows for
step
-
by
-
step execution of source code.


Xdebug is a d
ebugging extension that integrates with an apache web server or be used with LAMP,
WAMP, and MAMP

(web development environments that can represent production server with Apache,
MySQL and PHP releases)
.
Xdebug acts as a remote debugger. This means that the

client can be run on
another system than the one with xdebug installed.

Xdebug contains most of the same abilities that
other debuggers have. Clients can step through code line
-
by
-
line. This allows for the deep inspection of
variables.

Xdebug also
allows

for live editing of code.


The rest of this document give
s instructions for setting up xdebug
on a linux server and access that
functionality via Netbeans
.



Installing
Xdebug

using LAMP


Resources

Online instructions for this process may be found at:


1)
http://ubuntuforums.org/showthread.php?t=525257


Instructions for
integrating use with Netbeans
:


2)
http://wiki.netbeans.org/HowToConfigureXDebug#Overview


Setup


This setup is assuming acce
ss to PECL through command
-
line,
Apache 2 and PHP5
are
working
correctly
, and root access
. This setup will install the latest version of xdebug available in PEAR
repository.


Specific workflow (commands):

1.

First be sure PHP5 and pear are installed.

Open terminal on a linux box.

>
sudo apt
-
get install php5
-
dev
php
-
pear

2.

Install xdebug through PECL

>
sudo
pecl install xdebug

3.

We now need to find where the compiled module went (xdebug.so).

>sudo

find /
-
name ‘xdebug.so’

/usr/lib/php5/20090626/xdebug.so


4.

Next we need to edit the php.ini file.

>
sudo
gedit /etc/php
5
/apache2/php.ini

Add
/Edit

the following line
s. If debugging remotely, be sure to replace “%YOUR REMOTE HOST’S IP
ADDRESS%” to the remote host’s IP address
. If there are multiple developers, or you have an
unknown IP, add xdebug.remote_connect_back=1 instea
d of xdebug.remote_host

z
end_extension=”
/usr/lib/php5/20110919/xdebug.so


xdebug.remote_enable=1

xdebug.remote_handler=dbgp

xdebug.remote_mode=req

xdebug.remote_host=
%YOUR REMOTE HOST’S IP ADDRESS%

xdebug.remote_port=9000


5.

Restart apache for the changes to

take effect.

>sudo /etc/ini
t
.d/apache2 restart


6.

Test debug is loaded correctly.

You should see the correct PHP version, patch number, and
copyright.

This result should show Xdebug as an extension to Zend

>php
-
v


PHP 5.3.2
-
1ubuntu4.9 with Suhosin
-
Patch (cli) (built: May 3 2011 00:45:52)

Copyright (c) 1997
-
2009 The PHP Group

Zend Engine v2.3.0, Copyright (c) 1998
-
2010 Zend Technologies


with Xdebug v2.1.2, Copyright (c) 2002
-
2011, by Derick Rethans

Installing Xdebug using LAMP Part II


Resources

Online instructions for this process may be found at:


1)
http://ubuntuforums.org/showthread.php?t=525257


Setup


If you are having trouble with using an apt
-
get install, most likely the issue is with compatibility with
PHP5+. In this case
, wget
-
ing binaries, unzipping, and making is your best bet. Please see the following
instructions to streamline your install.


Specific workflow (commands):

1.

Create temporary php page

2.

Echo phpInfo() from this page.

3.

Copy and paste results into
http://xdebug.org/find
-
binary.php
. This page will give you custom
installation instructions that will vary slightly from the following depending on your system setup.

If
you have permissions problems, use sudo.

> cd ~

>

sudo apt
-
get install php5
-
dev

> wget
http://xdebug.org/files/xdebug
-
2.1.
2
.tgz

> tar xzf xdebug
-
2.1.
2
.tgz

> cd xdebug
-
2.1.
2

> phpize

> ./configure

enable
-
xdebug

> make

> sudo make install

4.

Make sure you have something like the following in your php.ini
file:

If debugging remotely, be sure to replace “%YOUR REMOTE HOST’S IP ADDRESS%” to the remote
host’s IP address
:

zend_extension=”/usr/lib/php5/20110919/xdebug.so”

xdebug.remote_enable=1

xdebug.remote_handler=dbgp

xdebug.remote_mode=req

xdebug.remote_host
=%YOUR REMOTE HOST’S IP ADDRESS%

xdebug.remote_port=9000



Xdebug with Netbeans:

Resources

Instructions for
integrating with Netbeans may be found at
:

1)

http://wiki.netbeans.org/HowToConfigureXDebug#Overview


Setup

1.

Create a new project

File > New Project…

2.

Under Categories: choose PHP. Then select PHP Application from Remote Server (if files on
remote apache server).

Click next.

3.

Give your project a name, source Folder. Select PHP version 5.3, and click next.

4.

Remote Configuration

a.

Enter your project URL. (ie.
http://joseph.cedarville.edu/myProject
)

b.

Create/Manage a remote connection to your server

i.

Ensure correct credentials, and give your initial directory the location that you
would like to begin file transfer. Be sure to test the connection.

c.

Set your upload di
rectory to wherever your files will be located on the server. (ie
joseph/var/www/myProject)

d.

Click Next

5.

Select the files you wish to download, and then continue.

6.

On remote client access your ‘Options’ Settings

a.

MAC users: Window > Options

b.

Windows users: Too
ls > Options

7.

In the above icons, click “PHP”. Under the “Debugging” header ensure your Debugger Port
matches the xdebug.remote_port port number in your php.ini file. You can leave the Session ID
as default.