PHP can't connect to Xdebug client on Docker - php

I am using WSL2 with installed docker-ce with PHP 8 and Xdebug 3. After a lot of debugging I figured out that simply PHP can't connect to Xdebug client for whatever reasons. It works when I am using telnet. Logs are empty, not information at all why connection does not work.
I downloaded dbgpClient to make sure it's not IDE issue (PhpStorm) from Xdebug page. ./dbgpClient -1 started it like this. When I do telnet host.docker.internal 9003 inside the container i have:
Connect from 172.20.0.5:45144
However if I try running for example php8 -dxdebug.mode=debug -dxdebug.client_host=host.docker.internal -dxdebug.client_port=9003 -dzend_extension=xdebug.so -dxdebug.start_with_request=yes index.php it just doesn't work, it never says it connected. Any idea what's going on?
I already checked things like php -m, it says Xdebug is there.

I had to add XDEBUG_MODE="debug" environment variable, from docs:
string xdebug.mode = develop #
This setting controls which Xdebug features are enabled.
This setting can only be set in php.ini or files like 99-xdebug.ini that are read when a PHP process starts (directly, or through php-fpm), but not in .htaccess and .user.ini files, which are read per-request.
Source - https://xdebug.org/docs/all_settings#mode

Related

Trying to install Xdebug on my remote server with PhpStorm

I have a remote machine where runs an Apache Server. I want to use Xdebug on my local machine, using PhpStorm, to debug the PHP files located in my remote server.
Here is what I did on my remote Ubuntu server :
1. apt-get install php7.2-xdebug
2. Go to /etc/php/7.2/apache2/php.ini and add :
[xdebug]
zend_extension=/usr/lib/php/20180731/xdebug.so
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_host=<my local machine IP without braces>
xdebug.remote_log="/var/log/xdebug.log"
xdebug.idekey=PHPSTORM
3. Restart Apache server /etc/init.d/apache2 restart
4. When I create a script with echo phpinfo(); in it, it shows that Xdebug has been installed "correctly" (I guess) : it shows an Xdebug section with all the variables.
5. In PhpStorm, I set a breakpoint on a file, and I start listening to incoming debug sessions, I verify this by doing a netstat query that returns that my Mac has its process PhpStorm listening to port 9000
6. In Chrome browser, I download the extension Xdebug, and I open my script, where I added the breakpoint. The mapping between this file that I open in Chrome and the local files is correct.
7. I tap the button "debug" in the Chrome extension, it becomes green. I verified, the cookie is correctly sent as http headers has XDEBUG_SESSION=PHPSTORM
Despite all of this, I cant achieve to have any incoming session on PhpStorm.
I tried to see file /var/log/xdebug.log that I registered to be the log file of Xdebug, but this file is empty....
Did I forget something ? I have no idea what to do its been 8 hours I'm on it I have seen all post related to it on StackOverflow but nothing worked for me (I can't even manage to have something in /var/log/xdebug.log so I could see deeper what's going on). I have no idea if Xdebug is doing something when it receive my HTTP request.
you phpstorm'configure is maybe error.

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.

Unable to setup xdebug for PHP in Intellij

I am trying to setup the debugger using xdebug and IntelliJiDEA 14.0.4 with my PHP application that runs at my localhost for Unit Testing and tracing. i have tried my best but could not able to locate where is the issue.
My phpinfo page shows xdebug support enabled Version 2.4.0.
It is the same version suggested by https://xdebug.org/wizard.php
In IntelliJ I have Run/Debug configrations I have configured "PHP Web Appication" with
Start url - http://localhost:8081/baskar/index.php
Servers - 172.20.65.71 : 9000 xdebug
In Validate remote environment - i have given deployment server as Local and validation script path as C:\dev\baskar\Validation. On validate I am getting
!No php.ini file was found
!No debug extension is loaded
My php.ini file settings:
extension=php_oci8_11g.dll ; Use with Oracle 11gR2 Instant Client
zend_extension=C:/dev/php_5.4/ext/php_xdebug-2.4.0-5.4-vc9.dll
[xdebug] xdebug.remote_enable=true xdebug.remote_port=9000
xdebug.profiler_enable=1 xdebug.remote_host=172.20.65.71
xdebug.profiler_output_dir="C:\dev"
xdebug.remote_log=C:\dev\php_5.4\xdebug.log
Please guide me where I went wrong or let me know if you need anyother info. Thanks in advance!!!
I know this is old, but I would like to provide a generic solution for a very common problem.:
Intellij Ultimate 2018.3 has an excellent Pre-configuracion instructions, with validation (check step 1). Open settings (CTRL+ALT+S) and find it following the selected option in the capture:
Take your time, all you need is in these configurations steps.

how can i associate/use PDT with eclipse in ubuntu?terr

I want to use PDT to debug PHP with eclipse. I am using ubuntu 9.04.
Can any one help me? please give details if possible.
Considering this thread and this one:
You have to ensure that xdebug is definitely loaded on the version of php you are using.
To do this, use the launch configuration you are using to try to run your script in debug mode and change it to run a script with phpinfo.php in it.
Also a Debug log would be good.
Add:
xdebug.remote_autostart=On
xdebug.remote_log="c:\temp\xdebug.log"
to your php.ini.
Then you have to insure that PDT is expecting Xdebug information on port 9000,
and have insured that your local Default PHP Web Server is http://127.0.0.1.
With the log, you might discover, for instance, that your php.ini files is not properly formatted, which could be enough to prevent you debugging PHP from PDT.
UYu would have to install PHP5 xdebug extension first,
sudo aptitude install php5-xdebug
after you would have to check your settings by editing /etc/php5/conf.d/xdebug
after you have to setup your php project to use xdebug and you should be done.
I'm use PDT in Ubuntu 9.04 and can fine debug my php projects.
first as already answered install php5-xdebug through apt-get or synaptic (I'm think you already install php5 itself in same way :) ). Then you must define php executables in Window/Preferenses/PHP/PHP Executables. You can point to /usr/bin/php, or can use 'Search...' button, but you must point initial search dir to nearest to your php exec binary. After found executable it always set to use Zend Debug by default. Edit executable to change 'PHP debugger' type to XDebug. And now a main trick. When you try debug your php scripts without create run configuration - it will always use Zend Debugger. You must create your own run configuration with XDebug setted as PHP Debugger. It's worked for me.

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