This topic is locked

Guide 22 - Debugging PHP code, line by line

7/18/2021 7:18:23 PM
PHPRunner Tips and Tricks
fhumanes author

img alt
I've been thinking about this article for a long time thinking about Phprunner users or really, it's going to be a complexity for those who use the product to generate simple examples of managing data.

In the end I have decided that you will be those who must say if you are interested in this topic or better not get into many trouble.

I use it and with him I learn a lot, because it allows me to run PHP programs, be able to stop the execution at a point and go, line by running the code section that interests me to review because it does not do what I understand should do. In summary, it is a programming and validation environment of PHP code.

Objective

Have a development environment where I can debug PHP code and be able to observe, line a line the evolution and content of the variables of the application.

Proposed technical solution.

First of all, if your work is to develop code, you must install and work with Microsoft Visual Studio Code (it's free). It is excellent for working with PHP but for me it seems to me that to begin with it is much simpler to start and understand the NetBeans development platform, now Apache and that is also free. So this is what I am going to explain and depending on acceptance, we will see if at another time I decide to tell you how to use the Microsoft platform.

First of all, indicate that what I am going to explain is to install on a computer with the following characteristics:

  • Windows 10 (64 bits)
  • Apache server.
  • Php 7.3 or similar version

It is worth any XAMP or other distribution version.

All detail and video of use on my portal

fhumanes author 7/18/2021

To begin, you have to download and install the following software:

  1. NetBean 11.3 https://netbeans.apache.org/download/nb113/nb113.html. You can see that there are higher versions, but beware, when I have tried them I have had problems with phprunner as both use the JNODE engine and have incompatibilities problems. With this version, there is no problem.
  2. XDEBUG PHP7.3 VC15 (64 bits) TS: Version 2.9.8 https://xdebug.org/download/historical. As in the previous case, NetBeans' compatibility with Xdebug is in 2.x versions and is incompatible with 3.x versions. Look that TS is in bold and it is so that we do not confuse us because this is the version that we are going to need. Adjust the DLL to the PHP version you have.

In my case, I have the PHP installation on "C:\PHP", so the XDEBUG DLL has saved it in "C:\PHP\EXT".

Now we have to indicate the PHP that activates the debug and we do this including these lines at the end of the file "php.ini" that I have it in "c:\php\php.ini".

; NETBEANS
zend_extension="C:/PHP/ext/php_xdebug-2.9.8-7.3-vc15-x86_64.dll"

xdebug.remote_enable=on

xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
; Port number match debugger port number in NetBeans IDE Tools > Options > PHP
xdebug.remote_handler=dbgp

To make it work you have to stop Apache and restart it again.

With this we already have everything we had to install and now we only have to try it.

There are many videos on YouTube where to explain how to use NetBeans to debug and I propose to see:

Continue reading in my portal

C
ckranichDevClub member 7/21/2021

Dear F Humanes,

Many thanks for your posts!
They all are very helpful!

I am very keen trying this out. Until now I used the "poor man's debug methods"
(sending messages to a syslog server; dumping variables to a textfile open in notepad++)
which are neither comfortable nor fast.

Kind greetings,

ckranich
D
DRCR Dev 9/10/2021

I too have used the poor man debug for too long. Thank you. This will make a big difference in my work. I often spend 2 days trying to fix 1 line of code.
THANK YOU so much for always sharing.
-Cec

B
BobAlstonNEW 10/8/2021

I have viewed your video and tried to install and use Netbeans as you suggested. I think I got the netbeans configuration right. I can see the project in the left side of Netbeans. But so far I can't get it to do anything useful.
Can you point me to more education/training/videos on netbeans and PHP

Thanks
Bob

fhumanes author 10/8/2021

Hello there:

Have you tried to follow the videos that there is and the Internet about PHP debugging in NetBeans?

The most important thing is to verify that if it indicates "Debug" the project at the end of the screen indicates that the product is prepared.

If you continue to give you problems (after watching the videos on YouTube) write me to my email fernandohumanes@gmail.com

img alt

Greetings,

fernando