Debug PHP code in Netbeans

Netbeans is a powerful IDE for PHP and many other development environments. is it possible to debug your PHP project in Netbeans? run your PHP code line by line and look at your variable values in real time? The answer is Yes! even you can have many watch expressions to examine variable values and execute your PHP code line by line. You just need to follow these 4 steps to enable PHP debugging in your Netbeans IDE!

Note - Netbeans version 8.0.2 has used for this article

 

 

Step1: Set php.exe file location on your web server.

Click on Tools-> Options to open Options dialog box on Netbeans then go to PHP tab and set the php.exe file location (I am using xampp server, your path also will be similar to "F:\xampp\php\php.exe" if you use xampp, or if you use wamp server your path will similar to "F:\wamp\bin\php\php5.4.12\php.exe")








 

 

Step2: Setup debugging on Netbeans

Go to Debugging tab on Options dialogbox and set the values as you can see on following screenshot. Then click on Apply and OK to save your changes.

 

 

 

 

 

 

 

 

 

Step3: Setup php.ini file

Copy following lines to the end of your php.ini file.
Note - you can find this file on a similar location as  "F:\xampp\php\php.ini" if you are using xampp, or "F:\wamp\bin\php\php5.4.12\php.ini" if you are using wamp server.

[xdebug]
xdebug.remote_enable = on
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "F:\xampp\tmp"
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
xdebug.remote_port = 9000

Note - you can change xdebug.profiler_output_dir = "F:\xampp\tmp" to match with your own folder

Step4: Restart your web server and Netbeans IDE to apply the changes that we made.



Now your IDE ready for debug your project. click on icon or Debug->Debug Project to start debugging on Netbeans. once you start debugging your browser will open the web page and you can put some break points on your code, then these break points will hit depends on your user actions on your web page. So you can examine your variable values and program execution using following icons on netbeans IDE. (or you can find the same actions on Debug menu on the IDE)

 

2 comments: