Netbeans / XDebug broken breakpoints - php

I am setting up xdebug with netbeans for my PHP application, hosted on a local xampp installation (Windows 7)
The installation and command line tests were successful and working correctly according to the netbeans / xdebug documentation. However, when I add a breakpoint in my code, it appears as a "broken" breakpoint no matter where I place it in the code. When I run the app w/ debugger, it fails to stop at these broken breakpoints.
I've done a lot of searching but haven't come across a good explanation for this, anyone out there have suggestions?
Thanks

Solution 1:
You need to configure the correct mapping between project source code and Xdebug output. you coudl do it here:
Project Window -> right click on project name -> Properties -> Run Configuration -> Advanced -> Path mapping
Solution 2:
Check in php info if xdebug is properly configured. You could check it by phpinfo() in empty php file and run it in browser:
<?php
phpinfo();
Try to find:
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
Then in php.ini (you could check the location of this fiel in phpinfo() add this section:
[xdebug]
xdebug.remote_enable = On
xdebug.profiler_enable = On
xdebug.profiler_enable_trigger = On
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "c:/xamp/tmp"
xdebug.remote_handler=dbgp
xdebug.remote_port=9100
xdebug.remote_host=localhost
(make sure if this directory c:/xamp/tmp exists)
Then in netbeans in:
Tools -> Options -> PHP -> Debugging
Set:
Debugger Port: 9100
and select "Stop at First Line"
Save it and debug the applictaion it should work fine now.

Related

Debugging PHP code with Xdebug and PhpStorm

I'm trying to enable Xdebug. I'm working on Ubuntu and I have trial PhpStorm version 2021.1.1.4.
My PHP version is 7.4:
PHP 7.4.21 (cli) (built: Jul 1 2021 16:09:41) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies
with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
In file: /etc/php/7.4/cli/conf.d/20-xdebug.ini I have settings:
zend_extension=xdebug.so
xdebug.idekey=PHPSTORM
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
Symfony application is running on port 8000 and PhpStorm is listening debug like on the screen below:
I have also switched on the Xdebug Chrome extension:
What could be wrong? Why it doesn't stop on breakpoint?
EDIT:
Below I paste result of xdebug_info():
I was in the position as you, 3 months ago. Let me explain what i followed and got XDebug working. First of all download the latest version of Xdebug by copying and pasteing the output of your phpinfo() function https://xdebug.org/wizard
If you are on windows you need to place the .dll files of Xdebug in the php folder of your local server. Then open your php.ini and place the following lines at the bottom:
[xdebug]
zend_extension= <THE ABSOLUTE PATH TO THE XDEBUG FILE>
xdebug.mode=debug
xdebug.remote_enable=1
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.start_with_request = yes
xdebug.discover_client_host = 1
After you do that, open phpstorm on the settings/preferences tab go to the PHP Tab, go to the Xdebug section and enter Debug port 9000,9003, make sure can acept external connections is checked allong with the 3 checkboxes below from the Bebug port textfield.
Final step,close the settings window and at the top right corner of phpstorm press the red telephone icon to start listening for incoming connections.
Refresh your browser and phpstorm should pop up a windows prompting you to accept the debug session.
I hope this helped you a lot.

How to enable php-debug in Atom?

I have installed php-debug in Atom + its IDE dependencies. When I set a breakpoint the debug view opens saying The debugger is not attached, but when I am trying to do so it seems as if Atom doesn't recognize I have php-debug package installed and asks me to install a debugger.
I read on some places there is a toggle debugging setting on the package, but I can't see that option.
I'm using Atom 1.27.0 and PHP 7.2.4:
PHP 7.2.4 (cli) (built: Apr 12 2018 02:49:03) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
with Zend OPcache v7.2.4, Copyright (c) 1999-2018, by Zend Technologies
I could provide Xdebug configuration but seems like the problem is on Atom itself? Did anyone have this problem?
very simple
Download xdebug from https://xdebug.org/download.php, TS version for Apache
Copy it to php/ext directory
Copy below text in php.ini below all other extensions
zend_extension="D:/wamp/php/ext/php_xdebug-2.6.1-7.2-vc15-x86_64.dll"
[xdebug]
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1 # Not safe for production servers
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true
Restart Apache and Find "xdebug" string in <?php phpinfo()?>
Install atom-debug_ui, php_debug
Package > PHP Debug > Toggle
Apply break-points and Run a PHP file from browser and that's it.
If it ask for paths remote http://localhost/DIRECTORY_PATH_TO_PHP_FILE
and local is directory path to PHP file.
I had the very same message few days ago …
Breakpoint were acually hit, I could see this because of the browser's tab loading icon, but nothing was happening on Atom user interface. All I could do was clicking stop or detach buttons which caused xdebug to end session and terminate browser tab load.
Using PHP7.2.7, Xdebug 2.6 (Docker php-fpm-alpine); Atom 1.26.1 x64
TLDR; PHP-debug extension couldn't process the "Path mappings" value I entered in the configuration panel.
Opening the dev console in Atom allowed me to spot an error accuring as the debugging session gets initiated in PHP Debug extension.
Atom Debug (PHP Debug) Session initiated
logger.js? [sm]:43 Atom Debug (PHP Debug) [TypeError: Cannot read property 'endsWith' of undefined
at Object.exports.generatePathMaps (/hom…]0: TypeError: Cannot read property 'endsWith' of undefined
at Object.exports.generatePathMaps (/home/me/.atom/packages/php-debug/lib/helpers.js:80:34)
at /home/me/.atom/packages/php-debug/lib/engines/dbgp/debugging-context.js:112:37
…
This led me to read at the Github repository and quickly figure what was going on.
All I had to do was changing the "Path mappings" text field value I erroneous filled in the first place. The text field expects a JSON string, as we can see HERE, the path mappings should be an iterable/array made of objects. It has to loook like this:
[{"localPath":"/home/me/projects/my-project","remotePath":"/var/www/my-project"}]
Add more mapping objects if you have more than one project. Note that this setting is reflected in ~/.atom/.config.cson
This fixed the issue, the debug view do not pop anymore saying there is no debugger attached.
I also had this problem, with Atom 1.53.0, PHP 7.3, and XDebug 2.9.8. I could tell from netstat that XDebug was connecting to Atom, but there was no activity in the PHP Debug tab, and no messages in the Console or PHP Console to give a hint of what was (or wasn't) going on.
Unlike Stphane, I didn't have any path maps defined. But taking a hint from his answer, I clicked on the "Path Maps" button in the PHP Debug tab. Then a series of error dialogs popped up, which I was able to solve one at a time.
In my case, the errors all happened because the project I'd checked out had some Unix symlinks in it, which Windows didn't know how to interpret. I solved them by removing the symlinks, and copying into their place copies of the files and directories they'd been pointing to. After that, the PHP Debug pane worked as expected - although the Debugger still says "No debuggers installed".
Atom Told me Debugger is not Attached but i made it work.
i saw atom php-debug tutorial but had problems like debugger is not Attached.
i want to share the configurations which that tutorial didn't includes:
Xdebug.ini autostart and idekey
first in the tutorial xdebug config. configs it to run automatic.
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1 # Not safe for production servers
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true
but its getting debugger run for every request. so you can make it off as this:
xdebug.remote_autostart=false
after that you have to tell debugger to send debug to atom`s api by appending this to xdebug config:
xdebug.idekey=xdebug-atom
if you use php-fpm, you have to reload it additional to restarting your http-server:
sudo systemctl reload php-fpm.service
Browser Extension with correct idekey parameter
after that install the browser plugin which attach a cookie to tell xdebug to made this request debuggable.
if your plugin hasnt Atom config,
in your browser extention preferences make this:
IDE key: xdebug-atom
Atom 2 plugins Enable and disable atom-ide-ui-feature-debug
and after that in Atom editor itself:
after installing atom-debug-ui and php-debug .
from Edit -> Preferences -> Package
select package atom-ide-ui package settings.
section Enable Features -> Enable Debugger
make it Never enabled .
like this:
https://github.com/gwomacks/php-debug/issues/310#issuecomment-419751273
True Break Points
now from Packages -> Debug -> Toggle Debugger
another note is when you want to make break point in atom. there are 2 types of break point. Big blue Dots and small blue dots.
only small ones work for debugger.
like here suggested:
https://learnwithdaniel.com/2019/06/atom-php-debugger/
Make remote path and local path identical
after setup request from browser. and Atom Asks you remote/local path.
make them identical

How to ensure XDebug is installed correctly?

I've downloaded the PHP version of Netbeans from here:
https://netbeans.org/downloads/
And I've pasted the output from phpinfo(); here:
https://xdebug.org/wizard.php
I followed their instructions:
Download php_xdebug-2.5.0-5.6-vc11.dll
Move the downloaded file to .\ext
Edit C:\php\php.ini and added the following line to the bottom of my .ini:
zend_extension = .\ext\php_xdebug-2.5.0-5.6-vc11.dll
Restart the webserver (IIS 7.5)
I copied that line and pasted it at the very bottom of my php.ini file. Does it belong somewhere else? Under the [PHP] section?
When I run NetBeans, I've opened my project and went to Properties -> Run Configuration -> Project URL and updated that to the correct path (http://localhost/myApplication/).
When I press Ctrl-F5 (Debug Project) a browser window opens with the following in the address bar:
http://localhost/myApplication/?XDEBUG_SESSION_START=netbeans-xdebug
So it looks like it's installed correctly, but if I set a breakpoint in my index.php file it doesn't trigger. I've tried setting other breakpoints throughout the software and those don't trigger, either.
I noticed in Netbeans, this progress bar just moves back and forth:
Should it be doing something?
EDIT Just doublechecked phpinfo(); and now I see this:
Zend Extension: 220131226
Zend Extension Build: API220131226,TS,VC11
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
report_zend_debug: on, on
So it seems like it's installed... What am I doing wrong?
And here's a screenshot of phpinfo();: https://i.stack.imgur.com/noSx4.png

IntelliJ PHP debugger not connecting

I've set up php 5.6 and Apache on my Mac and have IntelliJ with the php plugin installed (2016.2). The problem is that the IDE doesn't want to connect to the local server.
I've added the following lines to my php.ini:
[xdebug]
zend_extension=/usr/local/Cellar/php56/5.6.24/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = "9000"
and when I run php -v I get:
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
and phpinfo() shows
xdebug.remote_enable On On
xdebug.remote_port 9000 9000
But IntelliJ shows:
xdebug.remote_enable 0
I've checked, that I'm pointing to the right php.ini (checked path and other changes appear when the file is edited).
I tried all configurations (including with an IDE key) but nothing seems to work.
Is there a way I can check if the debugging is really working (i.e. is it the IDE not recognizing something or is the server faulty), because at this point I don't know what the problem may be.
The best way is to collect xdebug log for such unsuccessful debug session to see what it has to say. Sometimes debug does not work for you (IDE shows no reaction) but xdebug actually connects somewhere just fine (e.g. another service .. as described below).
There is a chance that you will have php-fpm running on your computer (that depends on how you installed your PHP -- what tool you have used for that). Php-fpm by default uses the same TCP 9000 port as xdebug does.
sudo lsof -nP -iTCP -sTCP:LISTEN
Run this command in terminal -- it should tell (after filtering results on 9000 keyword) what services are already listening on that port.
If it's indeed php-fpm .. then changing xdebug port from default 9000 to any other (e.g. 9001 or any other usually unused port) in both IDE settings + php.ini will solve the issue.

Is ioncube loader working in my case?

I used Putty to install ioncube loader. Used php -v to check and it shows
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v5.0.19, Copyright (c) 2002-2015, by ionCube Ltd.
However, I inserted a page with the following code in my website to check:
<?php
phpinfo();
?>
but it doesn't show that ioncube loader is enabled.
I also used:
<?php
echo var_export(extension_loaded('ionCube Loader') ,true);
and it returned false.
My Server API is CGI/FastCGI so I have already included
zend_extension = /usr/local/ioncube/ioncube_loader_lin_5.4.so
in the following file /etc/php5/cgi/php.ini
I wonder if it's really working or not?
A common mistake over time is having a different major PHP version for CLI and the web server, so perhaps your website does not use PHP 5.4. Another gotcha is using a different php.ini for website and cli, or having a php.ini in the same location as a web request that, on a cgi system, overrides that main php.ini. The web server software or fastcgi pool in this case may also need to be restarted.
First of all, go to your terminal and type which php this will show you the directory of the particular php.ini file that is currently being used by the php installed on your computer.
Open the php.ini file and make you have added this line zend_extension = /usr/local/ioncube/ioncube_loader_lin_5.4.so before any other Zend extension is loaded on the php.ini file.
Also note that the ionCube loader ioncube_loader_lin_5.4.so will only for PHP 5.4.* only.
Make sure you have copied the file into the directory you stated, you can verify by tying cd ~ and then sudo find /usr/local/ioncube/ioncube_loader_lin_5.4.so to make sure the file is situated there, if it is the terminal will return the file name showing it found it.
Now save the changes made on your php.ini file and run the command sudo apachectl restart (for Apache servers) to restart your server.
Test with php -v from your terminal again.
Hope this helps.

Categories