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.
Related
I'm running a debugging session in Visual Studio Code. I was expecting two things to happen that didn't.
For a browser window to open when I launched 'run and debug'.
To see a list of variables and their values.
First, I downloaded the Xdebug extension.
Next, I set a breakpoint on my php file.
Lastly, I clicked the 'run and debug' button.
I'm hoping someone can offer some advice on where I'm going wrong.
Thanks,
Kyle
Check your ports, I recommend using some that you remember, example: default.
I recommend you install php with brew, since with MAMP, XAMP, etc. there is less information in case of error.
brew tap shivammathur/php
brew install shivammathur/php/php#7.3
This tool gave me a lot of headaches at work, however, on MacOs we have to do a lot of steps.
I recommend that you remember how to install it as it is, because sometimes Visual Studio Code changes the ports when updating.
Xdebugger installation
These three files are the most important to modify (with nano, vim, etc.)
php.ini
Location: /usr/local/etc/php/7.3/php.ini
...
; Local Variables:
; tab-width: 4
; End:
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9000
99-xdebug.ini
Location: /usr/local/etc/php/7.3/conf.d/99-xdebug.ini
zend_extension = "/usr/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so"
xdebug.mode=debug
xdebug.start_with_request = yes
xdebug.remote_autostart = 1
Visual Studio Code
settings.json
Important: xdebug.remote_port, Listen for Xdebug, Launch currently open script are the same port.
{
// 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": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
I am setting up VS Code for use with PHP and debugging, with the aim of having the ability to set breakpoints, refresh the page, and stop when it hits them (I know it's possible, but don't know how)
There are no errors/outputs apart from "nothing happens"
As it stands, I have the following set up;
Windows 11 home
Xampp v3.2.4 (manual upgrade of PHP from 8.0.3 has been done)
PHP Version 8.1.10
XDebug installed (used the wizard with phpinfo())
PHP Debug extension added to VS Code
launch.json added to a .vscode folder in my root directory
Xampp has ports for 80 and 443 for apache, and neither of these work
Other pages have suggested port 9003 which also does not work
To try and enable this, I have the following inside of my launch.json;
{
// 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": 9000
},
]
}
And a previous attempt (along with many others) was the following;
{
// 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": [
{
"type": "php",
"request": "launch",
"name": "Listen For XDebug",
"port": 80,
"pathMappings": {
"/var/www/": "${workspaceRoot}"
},
"xdebugSettings": {
"max_children": 256,
"max_data": -1,
"max_depth": 5
},
"runtimeExecutable": "C:\\xampp\\php\\php.exe"
}
]
}
My php.ini has the following settings;
[xdebug]
zend_extension=xdebug
xdebug.mode=debug
xdebug.profiler_enable=1
xdebug.profiler_output_dir="C:\xampp\tmp"
So, in the end, this was an ini issue on the PHP end.
Using the same launch.json (changing port to 9003) config from above, and changing php.ini to be;
[xdebug]
zend_extension=xdebug
xdebug.mode=debug
xdebug.profiler_enable=1
xdebug.profiler_output_dir="C:\xampp\tmp"
xdebug.discover_client_host=On
xdebug.start_with_request = yes
xdebug.client_port = 9003
xdebug.mode = trace, debug
xdebug.collect_assignments = true
xdebug.collect_return = true
Seems to resolve the issue
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.
I am trying to debug a wamp-based website using VSC. When I start the debugger using the configuration Listen for XDebug, the Debug control panel opens. The Step Over, Step Into and Step Out controls are not active (I assume they become active when the program starts?). I have two breakpoints set up.
This is the launch.json file that VSC created for PHP:
"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
}
]
This is the XDebug config in php.ini
; XDEBUG Extension
[xdebug]
zend_extension ="c:/wamp64/bin/php/php5.6.31/zend_ext/php_xdebug-2.5.5-5.6-
vc11-x86_64.dll"
xdebug.remote_enable = off
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="c:/wamp64/tmp"
xdebug.show_local_vars=0
I changed these lines as per XDebug extension docs in VSC
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
When I start(submit a form), the code executes, but the VSC debugger doesn't engage, execution doesn't stop at the breakpoints, data is inserted in some tables. Am I missing some configuration so that the debugger does something, stops at the breakpoints? The VSC docs here
https://code.visualstudio.com/docs/editor/debugging
only highlight debugging with Node.js debugger. Appreciate any guidance on this.
I needed to ask for more info through comment section but I did not have enough reputation to do so :)
I suspect the PHP.ini file that you have modified is not the correct one. As you mentioned, you're dealing with WAMP, therefore there must be at least two PHP.ini files:
Command Line Interface (CLI)
Apache.
You should have modified the second one since you're running Apache.
I'm not quite sure about the exact path to those two files. I hope this could help.
How to know which PHP.ini is loaded?
Run phpinfo(); in your script in VSCode. It brings up your PHP configuration info. Look for: Loaded Configuration File.
I'm trying to debug my php with wamp, xdebug and this extension, but I can't get it to work. This is the end of my php.ini (C:\wamp64\bin\php\php7.0.4\php.ini):
[Xdebug]
zend_extension ="C:/wamp64/bin/php/php7.0.4/ext/php_xdebug-2.4.1-7.0-vc14-x86_64.dll"
xdebug.remote_enable=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir ="c:/wamp64/tmp"
My launch.json (C:\wamp64\www\CubePicker.vscode\launch.json):
{
"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
}
]
}
Settings.json:
// Place your settings in this file to overwrite the default settings
{
"emmet.syntaxProfiles":
{
"php": "html"
},
"php.validate.executablePath": "C:/wamp64/bin/php/php7.0.4/php.exe",
}
Can anyone see what I am doing wrong? I launch the debugger in VS Code, then run the webpage through my browser, which I assume is correct...? How can I fix this and make it hit the breakpoints I put in?
Let me know if you need anything else.
Thanks!
[EDIT]: I have been into phpinfo(), found the path of the loaded php.ini, and edited it to add the first chunk of code. This didn't fix the problem.
[EDIT]: I have also copied the whole of my phpinfo() here: http://pastebin.com/4Jk5TuQj
Author of the extension here.
As stated in the readme, you need to add
xdebug.remote_autostart = 1
to your php.ini so XDebug will actually make a request to VS Code.
I also searched your phpinfo() output but there was no XDebug section.
You should use the XDebug config wizard here: xdebug.org/wizard.php