I am trying to create a new report for my job's database.
Attempting to debug PHP in VSCode on Windows 10, running XAMPP on the local machine.
The site is in vue.js with a php api connecting to mysql 5.7 database. I use npm run dev for the crm in \khcc2\NETFOLDERS\UserName\htdocs\crm and need to debug the report.class.php api.
In php.ini
[XDebug]
zend_extension = C:\tempx\xampp\php\ext\php_xdebug-2.7.1-7.3-vc15-x86_64.dll
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = localhost
xdebug.idekey = "vscode"
xdebug.remote_port = 9000
In the api I have launch.json
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
}
I've tried adding to the launch.json each of these (not all at once):
"cwd": "\\\\khcc2\\NETFOLDERS\\UserName\\htdocs\\api",
"cwd": "h:\\htdocs\\api",
"cwd": "${workspaceRoot}",
and I sill get:
Unable to open 'index.php': File not found (file:///h:/htdocs/api/NETFOLDERS/UserName/htdocs/api/index.php).
Related
Once I performed all the configuration stuff, downliading the .dll, adding it to the ext path in xamp and to the php.ini etc.
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9003
zend_extension="C:\xampp\php\ext\php_xdebug.dll"
After adding both configs in vsCode:
1.- Installing the php debug extension
2.- Run->AddConfiguration->Listen for Xdebug
3.- Run->AddConfiguration->"Launch currently open script"
So both debug modes seem to be possible:
Surprisingly I can make the debug work if I "Launch currently open script".
De default config for the "Launch currently open script" is:
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
},
}
But that did not work until I added runtimeExecutable":"C:\\xampp\\php\\php.exe.
For the case 1.- Listen for Xdebug, that is to debug the whole app without the need of selecting an specific file, I could not make it work. The launch.json is:
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
}
I tried of course adding the runtimeExecutable":"C:\\xampp\\php\\php.exe, changing the ports, restarting apache and vs code and adding to de vs code settings the Allow Breakpoints Everywhere checkbox.
I am close, because for Launch current script mode works but when I launch vscode with the Listen for Xdebug option, my breakpoints are in place and my page is reloaded for check. Nothing happens and there are no errors in the vscode debug console.
Any idea of what needs to be done for the Listen for Xdebug to work and be able to debug the whole proyect with vscode?
Edit:
I also tried adding this options to my php.ini:
xdebug.mode = debug
xdebug.discover_client_host = 1
xdebug.start_with_request = yes
as recommended here
and the visualStudio php configuration Listen for XDebug 2 (Legacy)
Followed the intructions from the extension docs and I dont find what is wrong.
My php.ini configuration:
[XDebug]
zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
xdebug.mode = debug
xdebug.remote_autostart = on
xdebug.profiler_enable = on
xdebug.profiler_enable_trigger = on
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="c:/xampp/tmp"
xdebug.show_local_vars=0
xdebug.remote_host = 127.0.0.1
xdebug.remote_enable = 1
xdebug.remote_port = 9003
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="c:/xampp/tmp/xdebug.log"
My launch.json configuration:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9003
}
]
}
but i am still getting this error in error.log:
[php:notice] [pid 9388:tid 1840] [client ::1:63322] Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(, referer: http://localhost/online-store/admin/types/insert-types.php
First I used the port 9000 but it didn't work, then I tried changing the port in php.ini and launch.json to 9003 same as the port in error log but still nothing is happening and XDebug is not working and not stopping on breakpoints.
I also encountered with such an error after updting my Xdebug library to 3+ version.
What I found out is that new setting xdebug.start_with_request = yes configures Xdebug to establish a connection on every request.
Meanwhile the official doc offers to use xdebug.start_with_request = trigger in order to connect Xdebug only if the need for it was explicitly indicated. In this case I can start step debugging process with passing an extra key via GET parameters, for example http://localhost/?XDEBUG_TRIGGER=1, but this is inconvenient for me, all I want is press F5 within my VSCode to start debugging as I always did.
So my solution is the following. I left start_with_request = yes and turned off most of Xdebug notifications by passing xdebug.log_level = 0. Then i override log_level within launch.json file to enable all warnings but only within debugging session.
php.ini:
[XDebug]
zend_extension = php_xdebug-3.0.4-7.4-vc15-x86_64.dll
xdebug.mode = debug,develop
xdebug.discover_client_host = yes
xdebug.log_level = 0
xdebug.log = "%sprogdir%/userdata/temp/xdebug/log.txt"
xdebug.start_with_request = yes
xdebug.idekey = VSCODE
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"env": {
"XDEBUG_CONFIG": "log_level=7",
}
}
]
}
I encountered the same issue with PHP8. In my case, it was just the XDebug version suggested by their own wizard.
I use this version and it works just fine.
3.0.0-8.0-vs16
launch.json:
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"hostname": "localhost",
"pathMappings": {
"/var/www/html": "${workspaceRoot}/www/"
},
},
change pathmappings according to your requirements and the most important is hostname. after i added that, it worked
I am trying to use the PHP Debug extension in VS Code. I have followed the instructions and pasted the phpinfo contents into the wizard and downloaded the appropriate dll. I get the following error
launch.json
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
php.ini
[XDEBUG]
zend_extension = C:\PHP\ext\php_xdebug-2.9.6-7.4-vc15-nts.dll
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 9000
xdebug.remote_mode = req
If I choose the listen option having previousy started IISExpress I get this error
Error: listen EACCES: permission denied 0.0.0.0:9000
at Server.setupListenHandle [as _listen2] (net.js:1211:19)
at listenInCluster (net.js:1276:12)
at Server.listen (net.js:1364:7)
at c:\Users\me.vscode\extensions\felixfbecker.php-debug-1.13.0\out\phpDebug.js:236:24
at new Promise ()
at createServer (c:\Users\me.vscode\extensions\felixfbecker.php-debug-1.13.0\out\phpDebug.js:184:40)
at PhpDebugSession. (c:\Users\me.vscode\extensions\felixfbecker.php-debug-1.13.0\out\phpDebug.js:240:27)
at Generator.next ()
at c:\Users\me.vscode\extensions\felixfbecker.php-debug-1.13.0\out\phpDebug.js:7:71
at new Promise () { code: 'EACCES', errno: 'EACCES', syscall: 'listen', address: '0.0.0.0', port: 9000 }
If I choose the other option and start VS Code first, I get an IISExpress error
Failed to register URL "http://localhost:9000/" for site
"XXXXXXX-0f34f450-230f-4d11-8878-1a90a024dcf6" application "/".
Error description: The process cannot access the file because it is
being used by another process. (0x80070020)
I know port 9000 is not used because if I run this command when nothing is running it shows nothing running
Get-Process -Id (Get-NetTCPConnection -LocalPort 9000).OwningProcess
Clearly both sides can start port 9000 but they are not happy sharing the same port. What am I missing?
My mistake was the site was also running on the port 9000. It needs to be a completely different port to XDebug which listens on its own port.
iisexpress.json
{
"port": 1785,
"path": "C:\\YourSite",
"clr": "v4.0",
"protocol": "http"
}
working on ubuntu 19.10 and trying to get started with debugging my code in VScode, but after installing an extension - nothing works(buttons are disabled).
Using php7.3, in php.ini added several lines:
zend_extension=/usr/lib/php/20180731/xdebug.so
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_port=9000`
apache2 installed, but for now use build-in web server
my php.ini config sees the params i've added also.
the .json file VScode made itself is:
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]}
Use this configuration
zend_extension=<path_of_the_extension>
xdebug.default_enable = 1
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.idekey = VSCODE
xdebug.remote_handler = "dbgp"
xdebug.remote_port = 9000
xdebug.remote_log=/var/log/apache2/xdebug.log
xdebug.remote_timeout = 500
Also be sure that the php.ini file is the right one, using phpinfo(); function. The first lines show the path
phpinfo()
PHP Version => 7.4.7
...
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc/php/7.4/cli
Loaded Configuration File => /etc/php/7.4/cli/php.ini
...
In my case, this configuration was written in /etc/php/7.4/mods-available/xdebug.ini instead of the php.ini because XDebug was installed in Ubuntu from repositories
In Visual Studio Code (1.9.1) (mac) i have setup the php-debug plugin.
In the debug screen i start 'listen for Xdebug'.
After this i open the index.php on my XAMPP server (local).
But nothing happens.
the blue bar at the bottom of the screen turns orange.
the step over, step into and step out buttons are greyed out.
Also the following error message occurs at the watched variables:
cannot evaluate code without an connection
I try to use breakpoints on the following code:
<?php
$i = 0;
do {
$i++;
if (!($i % 1)) {
echo('<p>$i = ' . $i . '</p>');
}
}
while ($i < 100);
?>
I am using XAMPP and in my php.ini file i use port 9000 for Xdebug.
zend_extension="/usr/local/Cellar/php71-xdebug/2.5.0/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote.port=9000
I installed Xdebug using homebrew.
Here is my php info:
phpinfo.htm
Xdebug wizard tells me Xdebug is installed correctly.
my launch.json file looks like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
Would anyone know what i am doing wrong?
After setting the xdebug.remote_connect_back = 1 in the ini file
as n00dl3 suggested debugging most of the time works, but once in a while i get the following
error in the debug console:
<- threadEvent
ThreadEvent {
seq: 0,
type: 'event',
event: 'thread',
body: { reason: 'exited', threadId: 1 } }
I encountered this problem as well, not with the same environment (NGINX server + php-fpm) but the same symptoms. It turned out to be caused by my xdebug configuration.
How I managed to diagnose it : by writing a simple PHP script for test just like OP did :
<?php
xdebug_info();
By browsing to it, I got a bunch of info on my setup, including :
xdebug.client_host => localhost
xdebug.client_port => 9003
whereas my xdebug was listening on port 9900 (default being 9000).
Steps to fix : just add the following lines to your php.ini or xdebug.ini (wherever the rest of your xdebug configuration lies) :
# This should match your xdebug.remote_host
xdebug.client_host=localhost
# This should match your xdebug.remote_port
xdebug.client_port=9900
xdebug.mode=debug
Then rerun a debug session in VScode, add some breakpoints, and re-browse to your script : my VScode window popped up, the execution was paused on the breakpoint and the variables where accessible in the debug pannel just like expected.
EDIT : don't forget to also :
add xdebug.mode=debug to your php.ini
restart webserver and php-fpm services.
It seemed the server root needed to be set
in the launch.json with localSourceRoot like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"log": true,
"localSourceRoot": "http://127.0.0.1/public_html/"
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
Now breakpoints are working like they should.
In my case, these two lines were missing from the php.ini file.
xdebug.mode = debug
xdebug.start_with_request = yes
Check xdebug.client_port
in page xdebug_info(); or phpinfo();
Config same port in launch.json of vscode
I just had this problem too.
Somehow, someday, without realizing it, I got version 3 of xdebug installed, and a lot of conf param name changed , see this SO question
So verifying the xdebug version with phpinfo for example can be worth a shot.
I am working with VSCODE devcontainer and I fix with the config below:
My launch.json for VSCODE
{
"version": "0.2.0",
"configurations": [
{
"name": "Xdebug",
"type": "php",
"request": "launch",
"port": 9003
}
]
}
I use Dockerfile with a RUN below to install xdebug:
RUN pecl install xdebug && docker-php-ext-enable xdebug
I find my xdebug config file in /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
I edit the file as below:
zend_extension=xdebug
[xdebug]
xdebug.mode=debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.idekey=VSCODE
Or you can add it in Dockfile like below:
RUN echo ' \n[xdebug] \n\
xdebug.client_host=host.docker.internal \n\
xdebug.mode=debug \n\
xdebug.start_with_request=yes \n\
xdebug.idekey="VSCODE" \n\
\n' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
mode This setting controls which Xdebug features are enabled. We’ve set develop to enable development aids, such as getting better error messages, and debug to enable step debugging.
client_host This setting tells Xdebug the IP address or hostname of the machine that is running your text editor or IDE.
start_with_request This setting determines whether a function trace, garbage collection statistics, profiling, or step debugging are activated at the start of a PHP request. Setting it to yes instructs Xdebug to always initiate a debugging session.