JetBrains Gateway : debug PHP with dbgpProxy failed - phpstorm

I spent hours trying to figure out how, but I can't manage to debug with JetBrains Client... The more I get when I load a page in a browser is
And then it stuck there. Page in browser is loading forever.
Launching dbgpProxy + JetBrains client register IDE
php -v output:
PHP 7.4.28 (cli) (built: Feb 17 2022 16:17:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies
with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans
Xdebug configuration :
xdebug.idekey=PHPSTORM
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.mode=debug
xdebug.log="/var/log/xdebug.log"
dbgpProxy launch command:
dbgpProxy -i 127.0.0.1:9001 -s 127.0.0.1:9003
JetBrains client configuration
PHP > Debug on host > Xdebug : debug port 9099
PHP > Debug > DBGp Proxy on host : IDE key : PHPStorm, Host 127.0.0.1, Port 9001
Browser extension : Xdebug helper v 1.0.6
NOTE : It worked like a charm with PhpStorm, but with JetBrains Client I miss something which leads the IDE closing the connection.

Related

How to open port 9000 on Windows 10 for Xdebug to work correctly?

While testing in PhpStorm, I get the following error in the logs:
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9000 (fallback through xdebug.client_host/xdebug.client_port)
Here is my Xdebug config in php.ini:
[XDebug]
zend_extension = c:\localserver\php8.0.2\ext\php_xdebug-3.0.3-8.0-vs16-x86_64.dll
xdebug.client_host=localhost
xdebug.client_port=9000
xdebug.discover_client_host=1
xdebug.profiler_append=0
xdebug.mode=debug
xdebug.start_upon_error=yes
xdebug.output_dir="c:\localserver\php8.0.2\temp"
xdebug.profiler_output_name="cachegrind.out.%t-%s"
xdebug.remote_handler="dbgp"
xdebug.idekey="netbeans-xdebug"
Windows брандмауэр выключен.
This error disappears when I configure XDebug to port 80
But still, I want to properly configure XDebug, for this I need to open port 9000. Please tell me how to do this?
After reinstalling the project, everything worked by itself, but I still don't know what was the cause of the error. I believe that the reason was that I created the project before I installed PHPUnit globally and configured XDebug. Although of course I could be wrong.

PhpStorm local debugging stopped working - Do you see problem in setup?

I used to have PhpStorm working brilliantly on my computer. No browser extensions. I could put breakpoints anywhere, go to some URL in browser, hit enter and then I would automatically be taken to breakpoint in given file. Files in project would open up automatically as I stepped through code.
Now, it is a total mess.
First here is my Xdebug info in the xdebug.ini (I don't specify anything Xdebug related in the php.ini):
zend_extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20151012/xdebug.so
[xdebug]
xdebug.remote_enable=on
xdebug.default_enable=on
xdebug.remote_port=9000
xdebug.remote_host=localhost
If I run php -v I get
PHP 7.0.15 (cli) (built: Feb 13 2017 10:30:54) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.15, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
iMac:xdebug-2.7.2 $
phpinfo() shows corresponding values set based on my .ini.
In PhpStorm I have PHP CLI set to 7.0, it is showing Xdebug 2.7.2.
Curious about that "Can't load xdebug" message, but php -v doesn't show same message. At first I had zend_extension defined in both php.ini and the xdebug .ini and would see that message when doing php -v but after removing from php.ini the message went away from php -v.
I have no idea if I need to do anything under Debug settings in Build, Deployment, but here is what is there by default:
Also, I have my project set to sync with a remote server but for debugging I don't want to use path mappings. That is how I had it before and PhpStorm messages about debug session ending and no path mappings found was never a problem.
Here is my Run->Config
In the past, I didn't worry about a start URL. No matter what URL I entered in browser it triggered debugging.
And here is what I have tried regarding path mappings:
I did that to see if it would fix things, but no.
My gut feeling says it is either a problem with Xdebug settings, my run->config, or the fact that I am using a virtual host and somewhere there is a localhost entry causing a problem.
So I am at a loss. If I select Listen for incoming... and go to URL, the focus does not go to PhpStorm with current breakpoint. I see in browser that things stopped and I go to PhpStorm and see that debug was triggered. But the second I hit step over or step into the debugging just ends.
Anything glaringly wrong with what I am doing?
Edit: Here is what I see in the xdebug log:
[89603] W: Creating socket for 'dev.courses.com:9000', poll success, but error: Operation now in progress (19).
[89603] E: Could not connect to client. :-(
[89603] Log closed at 2019-10-21 10:42:37
[89603]
[89603] Log opened at 2019-10-21 10:42:37
[89603] I: Connecting to configured address/port: dev.courses.com:9000.
[89603] W: Creating socket for 'dev.courses.com:9000', poll success, but error: Operation now in progress (19).
[89603] E: Could not connect to client. :-(
[89603] Log closed at 2019-10-21 10:42:37
Not sure the specifics of the error... Maybe this hints at something? The question I have is where in the config do I specify localhost vs my virtual host alias? Maybe that is what is messing things up?
You can find out what Xdebug is trying to do by using the xdebug.remote_log=/tmp/xdebug.log setting. This log will indicate which connection attempts are being made, and why they succeed or not.
Ok, so this turned out to be an xdebug issue, though not obvious at first.
Originally I didn't think to check the PHPStorm log. But the PHPStorm log showed
Argument for #NotNull parameter 'remoteFileUrl' of com/jetbrains/php/debug/xdebug/debugger/XdebugDriver.onBreak must not be null
Searching above error took me to
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001498520-xdebug-works-only-with-first-line
Turns out my version of PHPStorm is known to not work with xdebug 2.7 so I downgraded to 2.6.1 and all is well :-)
thanks,
Brian

PhpStorm not listening to breakpoints

I have been struggling for hours regarding Xdebug and PhpStorm but I cannot get it to work, I have done the following:
1. Installed Xdebug sudo apt-get install php-xdebug
2. Edited the php.ini file /etc/php/7.0/apache2/php.ini
[Xdebug]
zend_extension="/usr/lib/php/20151012/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM
xdebug.max_nesting_level = 512
xdebug.file_link_format = phpstorm://open?%f:%l
3. Check the version php --version
PHP 7.0.33-10+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Aug 7 2019 09:50:44) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.33-10+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
4. Restart the service sudo service apache2 restart
5. Configure PhpStorm
Go through - Settings >> Languages & Frameworks >> PHP
Set the PHP Interpreter, to do so; click on three dots [...] button
On the new window; click on plus [+] button and select /usr/bin/php from suggestion popup.
Save and close this window and select the interpreter
I set the breakpoint and started listening
I access the url http://localhost/debug/file.php and nothing happens. I honestly don't have much more to say, I will share some files you might see what I have wrong.
What files should I share? This installation is based on https://gist.github.com/thomascys/7bf160bfe354eb74a8bb8b75e19038f4
/etc/php/7.0/apache2/php.ini
[Xdebug]
zend_extension="/usr/lib/php/20151012/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM
xdebug.max_nesting_level = 512
xdebug.file_link_format = phpstorm://open?%f:%l
Now that you have setup PHP in PHPStorm, check your settings under "Languages and Frameworks", disclose the "PHP" entry and select the "Debug" option. The settings revealed include a link named "Validate debugger configuration on the Web Server." Click on it and attempt to validate. It will give you more details on PHP and XDEBUG. If validation passes then click on "Install browser toolbar or bookmarklets." and follow the directions. This adds bookmarks lets that will have your browser submit page request with the necessary cookies to trigger xdebug.

How to run a html file on localhost (any port)

I am creating a website using HTML, CSS and js with java for server side. I need to run it on localhost.
Extra info: I am using mac os x 11 (el capitan)
I have already tried python and node.js but it clashes with java
So i need a technology that won't clash with java and will help me localhost on mac
IIRC macOS comes with PHP preinstalled, and PHP has built-in web-server which should be enough for serving static content.
So, open Terminal.app and then:
cd your/project/dir
php -S localhost:8080
After than you can navigate to http://localhost:8080/ and see your site in the browser (given you have index.html in your project, otherwise there will be "Not Found" message).
There are more advanced and/or less terminal-oriented ways, of course, but since you already tinkering with python and node, another terminal command should not be a problem.
BTW, you might want to look at that terminal window from time to time, as it outputs nice log of what things were requested from server. Good if you want to check for invalid references, 404 errors, etc. Here is a sample output:
$ php -S localhost:8080
PHP 7.3.6 Development Server started at Sat Jun 22 20:00:28 2019
Listening on http://localhost:8080
Document root is /private/tmp/test
Press Ctrl-C to quit.
[Sat Jun 22 20:00:32 2019] [::1]:51640 [200]: /
[Sat Jun 22 20:00:32 2019] [::1]:51641 [200]: /style.css
[Sat Jun 22 20:02:35 2019] [::1]:51670 [404]: /oops.html - No such file or directory
As you can see, root folder (/, which was translated to index.html in my case) and a stylesheet (style.css) were requested and successfully delivered (code is 200). But non-existent file oops.html resulted in error (code is 404).
You can use caddy
Install: brew install caddy
To serve static files from the current working directory, run:
caddy file-server --browse --listen :2015
Caddy's default port is 2015, so open your browser to http://localhost:2015.

Xdebug ignores breakpoints (browser and CLI)

I've been trying to setup Xdebug on PHP 7.2 with nginx (or cli) with no avail so far. The breakpoints are simply ignored. Tried activating them with PhpStorm and manually using xdebug_break().
All of the methods are at least triggering Xdebug, as error logs say (you can see the code in question in the picture below), but nothing happens:
Log opened at 2018-04-21 07:50:31
I: Connecting to configured address/port: 127.0.0.1:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///Users/riseandcry/Projects/php/jobApplication/index.php" language="PHP" xdebug:language_version="7.2.2" protocol_version="1.0" appid="9859" idekey="PHPSTORM"><engine version="2.6.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2018 by Derick Rethans]]></copyright></init>
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="break" reason="ok"><xdebug:message filename="file:///Users/riseandcry/Projects/php/jobApplication/index.php" lineno="4"></xdebug:message></response>
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>
Log closed at 2018-04-21 07:50:31
my config is this:
zend_extension=/usr/local/Cellar/php72/7.2.2_13/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_connect_back=0
xdebug.idekey="PHPSTORM"
xdebug.remote_log=/Users/riseandcry/Projects/php/xdebug/xdebug.log
xdebug.extended_info=1
xdebug.force_display_errors=1
I don't have any other extensions loaded in PHP, and PhpStorm validation shows that everything is correct:
Also, I already reinstalled everything (PHP, nginx, Xdebug), with various methods and it still does not work. My guess is that it's either Xdebug or config at fault, but no idea what.
Would really appreciate some help. I also read pretty much all of the related questions on SO and other forums and since I'm here, you can guess the outcome...
You are on Mac and you are using nginx... This means that most likely you do have php-fpm installed and running. Problem is that php-fpm also uses TCP 9000 port by default ... so right now Xdebug is connecting there instead of PhpStorm (the xdebug log gives a good hint here, if you have seen such response before).
Unfortunately PhpStorm is unable (for whatever reason) to detect that Xdebug port is already used by another app on Mac (but does it fine on Windows/Linux).
You can verify that manually with this sort of command (look for the entry that uses Xdebug port and see the process name):
sudo lsof -nP -iTCP -sTCP:LISTEN
The solution is to change Xdebug port to be 9001 (or any other meaningful number) in both php.ini and PhpStorm settings.
P.S. You will need to restart all debug sessions / disable and enable "phone handle" icon if you are using it. Alternatively just restart the IDE.