How to enable php-debug in Atom? - php

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

Related

PHP Xdebug Laravel application in IntelliJ IDEA

Could you please advice me how properly configure Xdebug for Laravel application. I found a lot instructions for PhpStorm but they do not work for me as I'm using IntelliJ IDEA Ultimate.
What I have already achieved - I can debug single PHP script but not whole application. I cannot follow completely the instruction which is given for PhpStorm because on step when I need to configure Run/Debug Configuration I got stucked.
Much appreciation on any help in advance!
Okay, I gathered full instruction how to work with XDebug and IntelliJ Idea Ultimate to debug Laravel application and Windows specifically (if you use other OS the installation part will be different but other should be the same):
First of all you need to install XDebug itself and configure PHP to work with it. For that:
Find out which PHP version you use using phpinfo() you will need Version, Architecture and PHP Extension Build sections to complete next step.
Go to https://xdebug.org/download.php and download appropriate build. Basically it is dll provided for specific PHP you have installed
After that copy that DLL to Apache modules directory - for me that is D:\OSPanel\modules\http\Apache-PHP-7-x64\modules\ as I'm using OpenServer.
Put into php.ini file following configuration:
[Xdebug]
zend_extension="D:\OSPanel\modules\http\Apache-PHP-7-x64\modules\php_xdebug-2.6.0-7.1-vc14-x86_64.dll"
xdebug.remote_enable = 1
xdebug.remote_host = "localhost"
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_port=9000
xdebug.idekey="PHPSTORM"
where php_xdebug-2.6.0-7.1-vc14-x86_64.dll is name of dll I personally downloaded.
Restart Apache
Open your Laravel project and check your Debuggin configuration (File > Settings... > Languages & Frameworks > PHP > Debug): check XDebug section if Debug port is the same as you specified above (it should be, if you did not changet it previously)
Delete all your Run/Debug configurations
Install Xdebug Helper for Chrome or any other extension if your not using Chrome (Browser Debugging Extensions)
Hit Run > Start listening for PHP Debug Connections
Put break point in your project and open appropriate site context
Enjoy!
Hope that will be useful for community.

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

Netbeans / XDebug broken breakpoints

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.

XDebug / Apache / PHP / Eclipse skips breakpoints

I'm having problems with XDebug.
Configuration as follows:
Windows 7 64bit
PHP 5.4.6 Thread Safe 32 bit
Apache 2.4 Thread Safe
Eclipse PDT 3.0.2
The problem is that xdebug_break() calls are not working, and breakpoints entered through Eclipse also don't function. I can see that the extension is working, as it appears as a module in phpinfo(). When I call an uncallable method, XDebug outputs the relevant error messages.
I've modified Eclipse's web server path mapping, to no avail.
Here is my php.ini config:
zend_extension = c:/php/php_xdebug-2.2.1-5.4-vc9.dll
xdebug.remote_enable = 1
xdebug.remote_host = localhost
xdebug.remote_port = 8080
xdebug.remote_mode = req
Any help would be kindly appreciated...
First check that what version you are using of PHP in eclipse....
Check it through:
Window->preference->PHP->PHP Interpreter....
Version there should match with the PHP version.....
Reply if problem is not solved....
For all those, that are still fighting with this problem, some handy tips.
Check which version (package) of Eclipse you have? It turns out, that Helios package has some bugs and doesn't stops on breakpoints, when you debug your application as Web Application. Debugging works only, if you run it as PHP Script. Which makes it pretty useless for debugging process.
You should consider either reverting to older Galileo Package Eclipse for PHP Developers or installing newest Eclipse Juno (or even newest developer version of Eclipse Kepler), which doesn't have PDT support build in, but you can easily add it to then, using Help > Install New Software.. (point it to http://download.eclipse.org/tools/pdt/updates/release).
These versions are reported to be able to debug as Web Application, respecting breakpoints.
Also, remember, that Xdebug must be run as Zend Extension in order to support breakpoints! In other words remove extension=xdebug.so (on Linux or xdebug.dll on Windows) line from your php.ini and replace it with zend_extension=/full/path/to/xdebug.so (on Linux or zend_extension=X:\full\path\to\xdebug.dll on Windows). Zend extensions requires full path, even if they're put into /php/ext folder, as regular PHP extensions. You'll find more info on this in Xdebug FAQ (look for an answer to "Xdebug is only loaded as PHP extension and not as a Zend Extension" question).

debugging php on mac?

was wondering what was the best way to debug PHP on my local machine. I use MAMP on mac os 10.5
thanks,
Patrick
Using xdebug is a good start. Download the package and follow the instructions in the INSTALL file. It's fairly easy. Once this is done, add the following lines to your php.ini file:
;;[xdebug]
zend_extension="/Path/to/your/module/xdebug.so"
xdebug.file_link_format="txmt://open?url=file://%f&line=%1"
xdebug.var_display_max_depth = 20
Don't forget to restart Apache after this.
Most debugging can be done using a simple die(var_dump($some_variable)). It's not very sophisticated, but with xdebug installed, the output of a vardump looks pretty good in a browser. In most of the cases this is enough.
If you need more control, you can add an xdebug_break(); statement in your code and add the following lines to your php.ini:
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
Again, don't forget to restart Apache.
Now, using a tool like MacGDBp (or Eclipse+PDT if you must), you get a classic debugger. You can step though your program.
Have fun!
I've always thought the "best" way of PHP debugging on any platform is by using FirePHP, which can output debug messages straight into the Firebug window in Firefox.
I've found that running php -l myfile.php is great at catching syntax errors before I try and reload the page in my browser (and thus prevent the abominable White Screen of Death). Beyond that, I just point my browser to my local webserver and try to access the pages.
You can do some nifty things in your code itself (like using debug_backtrace()), but that (obviously) requires you to put it in the code yourself.
Personally, I use Eclipse+PDT and XDebug. To simplify things, get Eclipse for PHP Developers from the Eclipse download page rather than installing PDT as a plugin. Eclipse has a high learning curve, but it gives you all the debugger functionality you expect: instruction stepping, breakpoints, watches, even altering variables live.
If you don't like Eclipse or find it's too much for you, there are other clients compatible with XDebug.
I also use eclipse+pdt and xdebug. If you're new to trying out debuggers you can try zend studio which will setup things pretty easily.
Zend Studio is by far the best tool to use to create and debug PHP code. I run the community Edition of Zend Server on my dev Linux box and locally in a virtual machine on my MacBook Pro.
Take a look at the Zend website for details - it has cut my app development by two thirds!
Thanks to a bunch of links like this one and others, here's a compiled solutions that successfully uses OSX's native Apache2 and XDebug together with MacGDBp and a Safari extension called XDebug Helper.
You can do it even without MAMP.
There is a way how to do it using:
PhpStorm
Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Php + Xdebug
1) Install php and debug
brew install php70
brew install php70-xdebug
In PhpStorm - check Preferences => Language and Frameworks => PHP
Php language level: 7
Interpreter: PHP 7.0.8 + XDebug (or choose from [...])
Check debug config:
Preferences => Language and Frameworks => PHP => Debug => Xdebug section
All checkboxes should be checked and set Debug port to: 9001
2) run server in your app's directory:
php -S localhost:8080
3) Add localhost:8080 to PhpStorm Preferences => Language and Frameworks => PHP => Servers:
Name: Localhost:8080
Host: localhost
Port: 8080
Debugger: Xdebug
4) Update php.ini:
Php => Interpreter => […] => Configuration file - Open in Editor
Add this section: (check zend_extention path through the cli)
[Xdebug]
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9001 (same as in Debug preferences)
5) Add Debug Configuration:
Run => Edit Configuration => add - Php Web Application
Choose Localhost:8080 server
6) Click Start Listening for Php Debug Connections
7) Set up breakpoints
7) Click on Debug (Green bug)

Categories