I have move from my Thinkpad laptop to HP Elitebook. I must set my development environment in my new laptop. After setup my Visual Studio Code and XAMPP in Windows 10 Pro 64 bit edition, I can't debug my PHP code.
I have properly installed Xdebug extension for Visual Studio Code, and make sure the php.ini correct. This is my setting for php.ini
(I use portable XAMPP which is placed on E:
drive):
zend_extension = "E:\xampp\php\ext\php_xdebug-2.4.1-5.4-vc9.dll"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_log="E:\xampp\apache\logs\xdebug.log"
And my xdebug.log show information like this :
Log opened at 2018-10-27 05:56:45
I: Connecting to configured address/port: localhost:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///E:/xampp/htdocs/absen/index.php" language="PHP" xdebug:language_version="5.4.3-dev" protocol_version="1.0" appid="7112" idekey="william"><engine version="2.4.1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2016 by Derick Rethans]]></copyright></init>
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>
Log closed at 2018-10-27 05:56:45
But my Visual Studio Code won't stop at breakpoint.
I have reinstall my Visual Studio Code, XAMPP, and using another Xdebug version but it still doesn't work.
I have follow these links:
None of these solutions work.
I saw the same issue, running ./vendor/bin/phpunit -c <config file>
was causing all of my breakpoints to be disabled. I was only able to debug if I checked "Everything" and sorted through all the junk.
I updated the pathMappings in my launch.json file, and added a new launch configuration with a different pathMappings to work locally
{
"name": "PHP Unit Test XDebug",
"type": "php",
"request": "launch",
"port": 9001,
"log": true,
"externalConsole": false,
"pathMappings": {
"${workspaceFolder}": "${workspaceFolder}"
},
"ignore": []
},
I found this solution from this SO post, and this one here Debugging PHPUnit tests in VS Code?
The reason might caused by the port of php xdebug.It works for me fine when I did this:
1.use php --ini
to show php config file and change xdebug port to 9900:
xdebug.remote_port=9900
then restart your php
2.open vscode and change the port to the same number in launch.json:
"port": 9900
3.enjoy your debug
Finally i know the source of problem. The HP Elitebook have preinstalled program named HP Velocity, which used port 9000.
The issue is port 9000 from my host is bind to port 9000 of HP Velocity software. When HP Velocity service connect to the localhost xdebug server, logs say that connection is ok, but it is connected to HP Velocity.
I changed xdebug port to 9090 in php.ini and changed in launch.json on visual studio code. After that, my visual studio code work as usual and can stop at breakpoint.
Hope this help others :)
In my case, the pathMappings
was incorrect, and did not change the port
{
...
"configurations": [
{
...
"port": 9000,
"pathMappings": {
"/var/www/yourproject": "${workspaceFolder}/",
}
}
]
}
My Breakpoints is actually working if I check the "Everything" breakpoint (It captured a suppressed exception, but VS code alerted that the file was no found)
"C:\\Users\\tonyg\\path\\LocalSites\\sitename\\app\\public\\": "${workspaceRoot}/"
Turns out the shell environment variable XDEBUG_MODE
overrides the xdebug.mode
setting in your php.ini
, and I was setting the XDEBUG_MODE
variable in my .zshrc
file (likely a configuration from a previous project that I had long forgotten about).
In short, if xdebug isn't working and you've seemed to follow all of the instructions about setting up your IDE and php.ini
file correctly, make sure you aren't inadvertently setting XDEBUG_MODE
somewhere else.
In my case, I was trying to debug a php script on my local machine, so I had to realize that I had to debug the php script using the port which the Web Server is using (8080 in my case) rather than using the port set on the VS Code configuration (I use 9090).
For anyone who is stuck with this error, this is my configuration:
1) httpd.conf
2) php.ini (XDebug section)
3) launch.json (VS Code configuration)
Please note if you are using Xdebug version 3.xx you need to do the following:
Stop Apache server, then in php.ini
add at the end of the file:
[XDebug]
xdebug.mode = debug
zend_extension="C:\xampp\php\ext\php_xdebug.dll"
After that, start Apache server agian.
Note that adding xdebug.start_with_request = yes
will tell xdebug to initialise communication with an IDE for every request even though you might not debugging, which gives a warning in your IDE console state:
[Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
It's better to use a chrome extension to trigger the activation of xdebug using a cookie in your browser. See https://xdebug.org/docs/step_debug#browser-extensions for more information.
In vscode go to Run
in your top menu, then Add configuration
, this will open launch.json
, add under configurations
:
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
},
Please note that port 9003
is different than your app port. I'm running my laravel app using: php artisan serve
with port of 8000
and in my launch xdebug is 9003
.
Re-run your debug in vscode and should be working. I wish you the best in your bug-fighting war!
I had same issue but after change port to 8000 in ubuntu it works for me.
This is what fixed the same issue i was having,worth the shot if previous answers didn't help
php.ini
[XDebug]
zend_extension = "C:\xampp\php\ext\php_xdebug-3.0.2-8.0-vs16-x86_64.dll"
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9000
xdebug.client_host = "127.0.0.1"
xdebug.log = "C:\xampp\tmp\xdebug\xdebug.log"
xdebug.idekey = VSCODE
launch.json
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"type": "php",
"request": "launch",
"name": "Run using local PHP Interpreter",
"program": "${file}",
"runtimeExecutable": "C:\\xampp\\php\\php.exe"
}
]
I am a novice programmer so this will probably sound dumb, but might be helpful to someone new to PHP and web servers like me.
I had the same issue with Xdebug skipping a break point. For me it turned out to be that I had a break point on an "echo" statement. Apparently that is not a valid line for using a break point. It started working once I moved the break point to a variable declaration.