XDEBUG is not working with PHPSTORM - laravel

From phpinfo() I can see XDEBUG is installed. I am using XAMPP and have configured the php.ini file in XAMPP like below -
[Xdebug]
zend_extension="/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/Applications/XAMPP/tmp"
xdebug.idekey=PHPSTORM
I am trying to run my Laravel project using PHP web application configuration in phpstorm but getting - Waiting for incoming connection with ide key ':random key:'.

Related

XAMPP services (PhpMyAdmin and Apache ) not working when add Xdebug

When I add Xdebug to the php.ini file, the Apache and PhpMyAdmin services are no longer available through the browser.
NOTE:
XAMPP version: last version (PHP 8.0.11)
Xdebug version : last version 3.*
php.ini :
[xdebug]
zend_extension="c:\xampp\php\ext\php_xdebug.dll"
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003

Issues connecting Vagrant Xdebug with PhpStorm 2020.3

Have spent over a day trying to get PhpStorm to debug a Drupal site inside a Vagrant virtual machine running Xdebug and I feel I'm close - but just not quite there yet.
Currently, in PhpStorm when debugging I have an error:
Waiting for incoming connection with ide key 'PHPSTORM'
In the Xdebug log in the VM (at /tmp/xdebug.log)
[2094] I: Checking remote connect back address.
[2094] I: Checking header 'HTTP_X_FORWARDED_FOR'.
[2094] I: Checking header 'REMOTE_ADDR'.
[2094] I: Remote address found, connecting to 192.168.88.1:9000.
[2161] E: Time-out connecting to client (Waited: 200 ms). :-(
[2161] Log closed at 2020-12-15 04:25:32
I tried setting up the Zero-configuration debugging without any luck.
For the debugging configuration, I have a PHP Remote Debug that validates correctly although it always defaults to the 'Local Web Server or Shared Folder' rather than the 'Remote Web Server' option.
When I started the project I set it up as a local web server option and I'm worried that I haven't changed the correct settings to now make this a remote web server. The connection type for the deployment is now 'Local or mounted folder' but originally this was 'In-place'.
Under Languages & Frameworks --> PHP --> Servers, I set this up on port 80, using Xdebug and without path mappings. I tried changing the port etc but then it doesn't validate so I'm confident that the server settings are correct and that PhpStorm is talking to the virtual machine correctly.
I changed the /etc/php/7.4/cli/php.ini file but phpinfo() says the configuration is coming from /etc/php/7.4/fpm/php.ini. The changes I made in the php.ini file are active though. phpinfo() is showing:
xdebug.idekey: PHPSTORM
xdebug.remote_host: 10.0.2.2
xdebug.remote_port: 9000
xdebug.remote_autostart: Off
xdebug.remote_connect_back: On
Really at a loss now as to what to try next. It is incredibly frustrating so hope someone can shed some light.
EDIT --- As per comment here is the screenshots of the setup:
Deployment: Local or mounted folder
PHP settings
The server setup
Debug settings
Validate the debugger from the remote server
Run Chrome with the debug addon running
The error message
The Run debug configuration settings
Start of the phpinfo with the config file showing where the xdebug settings need to be edited.
The Xdebug settings of phpinfo()
Some of the tests as per the comments:
After logging in to 'vagrant SSH' it shows the IP address to be used (10.0.2.2). The local computer is also IP 10.1.1.150 a telnet test of both of these works.
A 'sudo nano' of the Xdebug ini file
NOTE: Changing the remote connect back to 0 fixed the connection:
xdebug.remote_connect_back=0
And then the path mapping needed to be turned on in the Server settings and then everything was working correctly.
Big thanks to LazyOne for his helpful and thorough comments. :)
1) Check if there are separate php.ini files used by web server, -- you need to edit the right php.ini file.
Run phpinfo() and check to see if there is an ini file for Xdebug. In my case this was at /etc/php/7.4/fpm/conf.d/20-xdebug.ini
2) What's your Xdebug version?
Version 2 and 3 of Xdebug have slightly different parameters. In my case I was running Xdebug 2.9.5
3) What is the IP address of your Host OS as seen from the inside the VM? That's where Xdebug should connect (as it's Xdebug that connects to IDE and NOT other way around).
When you first log in to the SSH there will be an IP address shown. This is what the IP should be for Xdebug. In my example, this was 10.0.2.2
4) xdebug.remote_connect_back: On -- try set it off and ensure that you have correct xdebug.remote_host (as Xdebug v2 may not fallback to remote_host value when autodetected IP fails.
This fixed my connection!
sudo nano /etc/php/7.4/fpm/conf.d/20-xdebug.ini
Then change:
xdebug.remote_connect_back=1
To:
xdebug.remote_connect_back=0
Save, and then restart the server.
Test the connection again. After this step I had a connection between the host and remote server but I also had to turn on path mapping in PhpStorm to get the debugger working 100%.
5) Ensure that PhpStorm is the one that listens on Xdebug port when "phone handle" icon is enabled (use netstat or alike to confirm) and is allowed in firewall.
6) If you know the correct IP and sure that PhpStorm is listening -- you can just use telnet from inside the VM and try to connect to IDE on Xdebug port -- if connected then IP, port and firewall is most likely set up correctly.
Even with the error messages, the telnet check was working. So it pointed to the issue being with the Xdebug setup rather than the handshaking between the host and remote server.
Thanks to LazyOne's comments for finding the answer and for presenting a great workflow to help identify the problem.
I was experiencing something very similar to what you described.
I was able to start a debug session from the xdebug cli tool (dbgpClient) which proved to me that it was an issue with phpStorm.
My project is using a legacy version of xdebug. (2.2.7)
Downgrading to phpStorm 2020.2.4 resolved my issue.
(It's one-click in the jetbrains toolbox to downgrade)
Thanks for the answers in this issue. It took me half a day to find out that xdebug 2.2.7 with php5.3.10 doesn't work on Phpstorm 2020.3. So I downgraded to 2020.2.4 and it works again.

Xdebug not working when executing a Symfony console command in Homestead

When executing bin/console cache:clear the debugger won't stop on the first line of code.
The following output is shown in the xdebug log.
[18806] Log opened at 2019-02-04 15:58:42
[18806] I: Checking remote connect back address.
[18806] I: Checking header 'HTTP_X_FORWARDED_FOR'.
[18806] I: Checking header 'REMOTE_ADDR'.
[18806] W: Remote address not found, connecting to configured address/port: 10.0.2.2:9000. :-|
[18806] I: Connected to client. :-)
[18806] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///home/vagrant/projects/valkplanner2/bin/console" language="PHP" xdebug:language_version="7.3.0RC3" protocol_version="1.0" appid="18806" idekey="PHPSTORM"><engine version="2.7.0beta1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2018 by Derick Rethans]]></copyright></init>
[18806]
I am using PhpStorm 2018.3.3.
The following is my debug configuration in PhpStorm:
And this is the Xdebug configuration in /etc/php/7.3/cli/php.ini.
[xdebug]
xdebug.remote_enable=1
xdebug.remote_log="/home/vagrant/xdebug.log"
xdebug.remote_handler=dbgp
xdebug.collect_params=1
xdebug.remote_connect_back=0
;use `route -n` to find dev machine IP address from homestead environment (seems to default to 10.0.2.2)
xdebug.remote_host="10.0.2.2"
xdebug.default_enable=1
xdebug.remote_autostart=1
xdebug.show_local_vars=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir='/home/vagrant/profile'
xdebug.idekey=PHPSTORM
The debugger works just fine when I do a request with the browser or Postman using the ?XDEBUG_SESSION_START=PHPSTORM in the URL or the Chrome debugger addon.
The log suggests communication with xdebug works, but PhpStorm does not react.
Does anyone know what the problem could be?
Sounds like another service listening on Xdebug port instead of PhpStorm.
On Mac, PhpStorm cannot detect if Xdebug port is already used by another service or not (https://youtrack.jetbrains.com/issue/WI-29443).
You may use sudo lsof -nP -iTCP -sTCP:LISTEN sort of command to see what that service might be. Most likely it will be php-fpm (as it uses TCP 9000 port by default). On Mac & Linux, php-fpm quite likely will be installed on your dev machine (usually gets installed together with PHP).
Solution: change Xdebug port from default 9000 to some another port, most often it would be just next one -- 9001. Do it in both php.ini and PhpStorm (make sure that it's not listening to debug connections at that moment; if it does, stop and start again). If you are using some webserver (e.g. Apache) you may need to restart that as well (for PHP to read new config).

waiting for connection netbeans xdebug codeigniter xampp

While debugging in net beans code of php i got this message waiting for connection netbeans xdebug. I tried to resolve it but it wasn't work.Please help. i asm using xampp server on my localhost.

debugging laravel artisan from PHPStorm with homestead

I setup Laravel Homestead. I then configured both homestead xdebug.ini and PHPStorm to make the debugging work.
Here is my xdebug.ini inside homestead
zend_extension=xdebug.so
xdebug.remote_autostart = on
xdebug.remote_enable = on
xdebug.remote_connect_back = on
xdebug.remote_port = 9000
xdebug.idekey = "vagrant"
To start a debugging session the steps I follow are
In PHPStorm --> Start Listening for connections
In PHPStorm set a breakpoint
In my browser --> Use XDebug Chrome Helper OR add to my URL ?XDEBUG_SESSION_START=
Load the page
This works perfectly. My problem is when I'm inside homestead command line and I run a php artisan command then I can't get it to hit my breakpoints.
What I've tried
XDEBUG_CONFIG="idekey=PHPSTORM" PHP_IDE_CONFIG="serverName=server_name" php -dxdebug.remote_host="127.0.0.1" artisan mycommand
php -d xdebug.profiler_enable=On artisan mycommand
I also tried to set xdebug.remote_autostart=On then sudo service php5-fpm restart but still my breakpoints never get hit in PHPStorm
Two things are important:
remote_connect_back can not work in the CLI case because Xdebug can not detect the remote IP when you are in the console
When using homestead / VirtualBox in the NAT network configuration, your development machine (which is running PHPStorm) does not have the IP 127.0.0.1 seen from inside the VM. Instead, it has usually an IP like 10.0.2.2. To find out the correct IP, have a look at your Apache's access.log,
The following worked for me:
php -dxdebug.remote_autostart=on -dxdebug.remote_connect_back=off
-dxdebug.remote_host=10.0.2.2 artisan
edit If your breakpoints are not hit, you have to set up the folder mappings correctly (as your path in the IDE is different from what the web server sees:
Do export PHP_IDE_CONFIG="serverName=yourservername" in your VM, where yourservername is what you configured in the screenshot under "name"
Add a Php Remote Debug Configuration with an IDE key and the server configured above
And add your IDE key and the remote_host to the VM's XDEBUG-CONFIG
export XDEBUG_CONFIG="idekey=artisan remote_host=10.0.2.2"
References: http://randyfay.com/content/remote-command-line-debugging-phpstorm-phpdrupal-including-drush
Or, if that all is just too complicated or not working - you can trigger your artisan command via a url (route) using
Artisan::call('whatever:command');
In most recent versions of Homestead you can do xphp artisan whatever and phpstorm will popup a windows automatically.
https://laravel.com/docs/8.x/homestead#debugging-cli-applications

Resources