Xdebug connection not working with PhpStorm and Docker - php

I have a problem debugging PHP with PhpStorm. I have container, and it is running Ubuntu 18.04.2 LTS and my host machine is macOS 10.14.5. I added configuration to PhpStorm, but breakpoint is not hit.
So, this is my xdebug.ini configuration:
zend_extension=xdebug.so
xdebug.max_nesting_level = 250
xdebug.remote_port = 9000
xdebug.idekey = "XDEBUG_ECLIPSE"
xdebug.remote_host = "192.168.1.144"
xdebug.var_display_max_children = -1
xdebug.var_display_max_data = -1
xdebug.var_display_max_depth = -1
# Enable the debugging on request
xdebug.remote_enable = on
xdebug.remote_autostart = off
# enable logging
xdebug.remote_log=/tmp/xdebug.log
When I run php -m -v, I can see under Zend Modules that Xdebug is enabled/installed. My php version is PHP 7.1.32.
192.168.1.144 is the IP of my host machine. I also checked that PhpStorm is configured to listen on port 9000
When I created new configuration, I set IDE key(session id) as XDEBUG_ECLIPSE, also, when I defined server under configuration, host is correct (dummy.test), port is set to 80, and Debugger is set to Xdebug.
I also ran command tail -f /tmp/xdebug.log, and when I refreshed the page, there wasn't any new entry in the log file.
Any idea what am I missing? I set up breakpoint to one index function of xy controller and is not hit, I also enabled break at first line in PHP script.

so, with help of the topic owner it was found that for Mac host.docker.internal is set doc
as a hack-solution host ip was added to /etc/hosts inside docker container:
host-ip host.docker.internal
probably there should be a better solution :)

Related

Xdebug not creating log files

Looking for some advice. Changed servers and I have setup Xdebug. PhpStorm detects it enabled, so does PHP, although I cannot get it to work.
(Firewall port opened, my firewall disabled, settings all configured, but I am getting nothing)
In order to identify the issue, I need to be able to see the Log of Xdebug, but I cannot get it to output anything. I tried it without a log file, then I have also created a log file and given Apache access to it, but still nothing.
I am running CentOS 8
Apache - Log_Debug enabled
Running on php7.3
PHP - track_erorr enabled.
/opt/plesk/php/7.3/etc/php.d/50-xdebug.ini
; Enable xdebug extension module
zend_extension=xdebug.so
xdebug.default_enable = 1
xdebug.idekey = "PHPStorm"
xdebug.remote_enable = 1
xdebug.remote_autostart = 0
xdebug.remote_port = 9000
xdebug.remote_handler=dbgp
xdebug.remote_log="/tmp/xdebug.log"
xdebug.remote_host=123.123.123.123
(IP has been changed for obvious reasons)
Can anyone tell me why I cannot get Xdebug to write out any errors or connection attempts to: /tmp/xdebug.log
Here is my phpinfo() debug info:
Thanks for the comments, I didn't noticed Xdebug has updated its self.
After removing all previous reference i re-setup the the debug.ini
(I dont store custom ini settings in php.ini i reference them correctly)
Here is my updated xdebug.ini This works by using the browser Plug-in to enable to the Debugger mode
zend_extension=xdebug.so
xdebug.client_host = 123.123.123.132
xdebug.client_port = 9000
xdebug.connect_timeout_ms = 200
xdebug.force_display_errors = 1
xdebug.force_error_reporting = 1
xdebug.idekey = PHPStorm
xdebug.log = /tmp/xdebug.log
xdebug.log_level = 7
xdebug.mode = debug
xdebug.output_dir = /tmp
All default settings can be found here: https://github.com/xdebug/xdebug/blob/master/xdebug.ini

PhpStorm Docker & zero-configuration Xdebug

I am trying to set a zero-configuration debugging for PhpStorm/Docker/Xdebug.
Xdebug is installed properly (I can see it loaded on phpinfo()):
My PhpStorm setup for debugging is standard, listening on port 9000. Here is the xdebug config I'm using:
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = docker.for.mac.localhost
xdebug.remote_port = 9000
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 0
xdebug.remote_log = /var/log/xdebug.log
xdebug.idekey = "PHPSTORM"
Off topic: I am also wondering if using xdebug.idekey is the same as providing IDE key through Chrome extension?
When I click on PhpStorm to start listening for connections, and set in the configuration to break on first line, I am getting the following:
Looking at Xdebug logs, it is clear that container connected to client (which is also clear from the fact that I am getting an error when trying to debug).
At this point, I have no manual servers or remote debug configurations set up.
If I define a server and remote debug configuration, and set environment key:
environment:
- PHP_IDE_CONFIG="serverName=docker-server"
And then if I click to debug:
Debugging then works, and no errors appear.
But this is then not a zero-configuration debugging...
What am I doing wrong?

Netbeans waiting for connection to XDEBUG

Netbeans won't connect to xdebug. I've tried suggestions from the following posts:
Debugging IDE's port connection to XDebug: "Waiting to Connect"
netbeans shows "Waiting For Connection (netbeans-xdebug)"
but it doesn't fix my issue.
It seems Netbeans connects to xdebug because while it waits for the connection all request made to the webserver [Apache2] are blocked. Also the port [9001] appears to be in use:
roxy#Pixy011 ~ $ sudo nmap -sS -O 127.0.0.1
Starting Nmap 6.00 ( http://nmap.org ) at 2013-11-28 20:48 EST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000029s latency).
Not shown: 990 closed ports
PORT STATE SERVICE
22/tcp open ssh
139/tcp open netbios-ssn
443/tcp open https
445/tcp open microsoft-ds
631/tcp open ipp
902/tcp open iss-realsecure
3306/tcp open mysql
8080/tcp open http-proxy
8081/tcp open blackice-icecap
9001/tcp open tor-orport <---- Opened by java
xdebug.ini: [I have confirmed it is loaded in phpinfo()]
zend_extension=/usr/lib/php5/20100525/xdebug.so
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_handler="dbgp"
xdebug.remote_mode="req"
xdebug.remote_host="127.0.0.1"
xdebug.remote_port=9001
xdebug.idekey="netbeans-xdebug"
Netbeans configuration:
Debugger port: 9001
Session ID: netbeans-xdebug
Stop at first line: Checked
All other options are unchecked
Project properties:
Host: 127.0.0.1
Port: 9001
Edit:
I've noticed Netbeans doesn't append the XDEBUG_SESSION_STOP to the URL. I don't think this is related to the issue because Netbeans only opens the page after I close the debugging session.
I've also disabled SELinux
On Ubuntu 13.04 64bit php 5.4.9-4 Xdebug v2.2.3 netbeans 7.4
I have same problem and have solve it by:
1. go on http://xdebug.org/wizard.php follow the instructions to compile your own xdebug.so
2. in netbean 7.4 general options (sorry I haven't reputation 10 to post image)
test connection. be sure correct settings on Proxy:
to me "No Proxy" is working.
3. in php options debugging tab change xdebug setting port to other than 9001 or 9000.
I choose 9002 but you can try until you find a free port (if port is not free nb tell you)
4. in php.ini OR for ubuntu users in /etc/php5/conf.d/20-xdebug.ini
zend_extension=/usr/lib/php5/20100525/xdebug.so #where you ave put your reconpiled xdebug.so
[xdebug]
xdebug.remote_autostart=0
xdebug.remote_enable=1
xdebug.remote_handler="dbgp"
xdebug.remote_mode="req"
xdebug.remote_port=9002 # the port you have found free and set in netbeans above
xdebug.remote_host=127.0.0.1
xdebug.profiler_enable=0
xdebug.profiler_output_dir="/tmp/"
xdebug.idekey="netbeans-xdebug"
xdebug.remote_log="/home/#user_name#/xdebug.log" #your user name
5. sudo service apache2 restart
after do this I can debug php again.
I had the same issue and I have tried many solution i had found out there but the issue still occured. I have tried to follow the step discribe in enter link description here
and
enter link description here
And that , whttp://localhost/abc/trunk/abc/backend/web/?XDEBUG_SESSION_START=netbeans-xdebughen i debug my project, my netbeats still waiting connection till i have to had the following "?XDEBUG_SESSION_START=netbeans-xdebug" in my url as http://localhost/abc/trunk/abc/backend/web/?XDEBUG_SESSION_START=netbeans-xdebug
so netbeans was able to connect with xdebug
**On Windows 10 with Netbeans 8.0 running Netbeans built in webserver **
The following options in the php.ini file resolved the issue for me:
zend_extension ='C:\path to php installation\ext\php_xdebug-2.5.0-5.6-vc11.dll'
xdebug.remote_enable=on
This issue for me seemed to be resolved by using the full path to the .dll file. Also, because I had spaces in the path name I had to enclose the path in quotes (double vs single did not seem to matter). Also, I had to set the xdebug.remote_enable option. Once I set both options, I was able to select the Debug Application option within Netbeans and the debugger started.
i was facing a similar problem, in my case i had recently update my php version and the xdebug configuration were in the only php5 folder. had simply had to copy the old xdebug configuration to the new php.ini file of the new version and it worked like before.
some of the tips to debug this are:
first check if xdebug is install, run (php -v) if xdebug details aren't there then install and add the configuration.
open phpinfo() under xdebug category check if xdebug configuration is loaded.Check for the following settings.
remote_enable = on,remote_handler=dbgp
I faced the same issue to get xdebug worked in virtualbox ubuntu machine with Netbeans.
PHP version 7.4
Changed following file
"/etc/php/7.4/apache2/conf.d/20-xdebug.ini"
and added following lines
zend_extension="/usr/lib/php/20190902/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_log = "/var/log/xdebug.log"
Plese note that the line below consists double quotes for defining the path.
zend_extension="/usr/lib/php/20190902/xdebug.so"
Had same issue:
$ netstat | grep 9000
...
tcp6 1 0 localhost:9000 localhost:37486 CLOSE_WAIT
Solution: Restart NetBeans.
There was running a dead Process waiting for connections.
Here Netbeans with a running debug session. Note the CLOSE_WAIT and TIME_WAIT.
tcp6 0 0 localhost:9000 localhost:38166 TIME_WAIT
For Xdebug v>=3
If you are still facing issues after trying all above answers. And you have Xdebug version >=3 then only try my steps.
Some settings have been changed in v3.
Xdebug's default debugging port has changed from 9000 to 9003. So change it in php.ini and netbeans IDE.
In php.ini
add xdebug.start_with_request="yes"
add xdebug.client_host = localhost . (The old xdebug.remote_host=localhost is no longer useful in v3)
add xdebug.mode=debug

Xdebug not working with PHPStorm

I use PHPStorm along with Xdebug to step through my code. PHPStorm is running on a Windows 7 machine, and my local webserver is running on a separate CentOS 6.4 machine. I've done a phpinfo(); to verify that Xdebug is being loaded by PHP, and it is. The following are the settings for my Xdebug in the PHP.ini:
[xdebug]
zend_extension="/usr/lib/php/modules/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_host = "192.168.1.130"
xdebug.remote_log = "/var/log/httpd/xdebug_log"
I similarly setup PHPStorm to use my CentOS server as the debugging server, and I listen for connections. I assigned static IPs to both of these machines. Using a Chrome Xdebug plugin to set the appropriate cookies, I attempt to set a breakpoint, but nothing happens. When I go to look in /var/log/httpd/xdebug_log (which has 777 permissions), nothing is written there. I've opened up port 9000, and I can telnet from my CentOS machine back to my Windows machine on port 9000 no problem. I also set SELinux to permissive, but to no avail.
Any ideas what could be happening here?
Try to configure your project in PhpStorm
Open Settings->Languages & Frameworks->PHP->Debug
Uncheck the "Ignore external connections through unregistered server configurations" option
OK
Add to your php.ini:
xdebug.mode=debug
I was having the same issue, below are the steps I performed to resolve it:
Make sure you have xdebug installed and in php.ini uncomment xdebug.mode=debug
Open Settings->Languages & Frameworks->PHP->Debug, Assign Debug Port value, you can find this port from php.ini. In my case, it was 9002
Now Validate debugger configurations - here you need to add the path to your web application files and URL. Click validate.
Now Start Listening -> Enable listening for PHP Debug Connection.
After this setup you can set a break point and start debugging with XDEBUG.
In my case, i added folder that im debugging to exclusive, so it return 502 or blank page when i put breakpoint. Remove exclusive folder and everything working.
You can consider this blog to find more solution: Link.
sudo gedit /etc/php/7.2/mods-available/xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_port = 9898
xdebug.idekey = “PHPSTORM”
xdebug.show_error_trace = 1
xdebug.remote_autostart = 0
xdebug.mode=debug
xdebug.client_port=9898

Xdebug stopped working, where do I look for errors?

I installed Xdebug and all was fine, until suddenly it stopped working. phpinfo() gives a nice XDebug output with all variables.
php -m | grep deb
also gives twice XDebug (for Zend and PHP), so again looks just fine. My php.ini has these lines:
zend_extension=/usr/lib/php5/20090626/xdebug.so
;extension=xdebug.so
xdebug.remote_host=localhost
xdebug.remote_enable=on
xdebug.remote_port=9001
xdebug.remote_handler=dbgp
xdebug.remote_connect_back=1
And yet, when running this code with should check XDebug (from Netbeans docs) it's just stuck. So No IDE is working with XDebug.
<?php
$address = '127.0.0.1';
$port = 9001;
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($sock, $address, $port) or die('Unable to bind');
socket_listen($sock);
$client = socket_accept($sock);
echo "connection established: $client";
socket_close($client);
socket_close($sock);
Also, according to XDebug installation, I went twice throught the steps. What is wrong with my config? Thanks.
At the end, left with only two solutions - to reinstall the Ubuntu OS or to install a new VM especially for xdebug, I'm going for the second one.
Funny thing is, everything was working according to the "RTM" (f=freaking). One thing that I couldn't figure out is how to read the logs for XDebug in order to understand where the real problem is.
UPDATE
After some struggling, I deleted every single line related to xdebug from every php.ini that I had. And moved these lines to /etc/php5/conf.d/xdebug.ini. Restarted Apache, and then PHPStorm, and it works.
P.S. in the middle, I tried to install xdebug with pecl, from github, and the standard Ubuntu version. I think the one that I compiled is currently working. And.. the log gets updated as well.
;xdebug configuration
zend_extension = /usr/lib/php5/20090626/xdebug.so
xdebug.remote_host = 127.0.0.1
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
xdebug.remote_mode = req
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
xdebug.remote_autostart=1
xdebug.idekey=PHPSTORM
xdebug.remote_log="/tmp/xdebug.log"
On your server, try this command:
$ netstat -anp | grep CLOSE_WAIT
Any :9000 entries will give you XDebug troubles; consider kill -9 <pid>.
I had this problem too on Ubuntu after updating php. For me, turning on html errors in php.ini got xdebug with Netbeans to work again ...
sudo vi /etc/php5/apache2/php.ini
display_errors = On
html_errors = On
And restart apache:
sudo /etc/init.d/apache2 restart
http://ubuntuforums.org/showpost.php?p=9592364&postcount=14
I checked my
netstat -anp
output and found out that there were number of open sockets (in XDebug port range) by master process on my remote machine [running xDebug].
Killing the 'master' process solved the problem for me.
Seemed like a port overrun situation for me.
Thought the information might be useful to some.
check port is not occupied, check netbeans is configured to listen to that port(i see you have 9001, 9000 is default usually)also when i debug with eclipse i have to "terminate and relaunch" the debug session every now and then since it stops working, never under stood why, i suspect some sort of expired debug session
Check are you putting breakpoints to the right file. Find first file where script enters (front controller). On symfony there can be more than one for example.
In my case after update xdebug to 3 version I just put/set php.ini config
error_reporting=E_ALL
display_startup_errors=1
display_errors=1
and then command php -v show all warnings and errors.
In my case:
Xdebug: [Config] The setting 'xdebug.remote_enable' has been renamed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-xdebug.remote_enable (See: https://xdebug.org/docs/errors#CFG-C-CHANGED)

Categories