0

I've read most all of the posts about setting up PHP Xdebug for VS Code but no solution for me. I've installed VS Code on a new laptop (that's relevant because I know what else is installed and there are no multiple instances of PHP - but there seems to be!)

I've installed XAMPP, which includes PHP 8.2.12 on a Windows 11 PC.

The php -v shows :

PHP 8.2.12 (cli) (built: Oct 24 2023 21:15:15) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans

The php.ini says:

zend_extension = c:\xampp\php\ext\php_xdebug.dll
xdebug.start_with_request = yes
xdebug.client_port = 9900
xdebug.client_host = 127.0.0.1
xdebug.default_enable=1
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_log="C:\xampp\apache\logs\xdebug.log"

The json settings in VS Code are:

{
    "workbench.colorTheme": "Visual Studio Light",
    "debug.allowBreakpointsEverywhere": true,
    "php.executables": { "v8.2": "//xampp//php//php.exe" },
    "launch": {      
        "configurations": [  {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9900,
            "pathMappings": {
                "c:/xampp/php/ext": "${workspaceFolder}"
            }
        }
    ]]
    }
}

According to all the posts I've read that should do it, but when trying to debug a simple PHP I get this error:

Failed loading C:\php\ext\php_xdebug-2.6.1-7.2-vc15-nts-x86_64.dll

Now I'm no expert, but this seems to be saying its trying to run PHP 7.2 and wants the Xdebug 2.6.1. non thread safe xdebug.dll.

But I can find NO other instance of php.exe on the PC - where in VS Code is it looking for c:\php\ext\ a folder which doesn't exist. I cant find in VS Code where such settings exist or how to tell VS Code to look in right folder (in this case c:\xampp\php\ext)

FWIW I'm using RobertLu's PHP debug extension though, I've tried all others available. On previous laptop some time ago I did have some success using Felix Beckers PHP Debug extension, but that is no longer appearing in VS Code list of available extensions.

Any comments or suggestions gratefully received.

3
  • You are also using a NTS (Not Thread Safe) version of the XDebug dll. It should be Thread Safe in WIndows Commented Nov 29, 2024 at 15:27
  • Im afraid neither of two comments is the least bit helpful though I know its easier to post a RTFM link than true perception. Please refer to my quote from the php.ini and say where it is wrong. Yes I do read docs before a post. As for NTS - the VS code error is referring to a PHP and xdebug which is simply NOT installed and theres nothing in that link which helps - the php_xdebug.dll IS the correct TS version as recommended by xdebug wizard. MY problem is WHY and how is VScode generating this error? which configuration or file (apart from php.ini, launch.json) needs to be changed and how? Commented Nov 29, 2024 at 21:39
  • Does the information here possibly help? Commented Dec 1, 2024 at 5:17

1 Answer 1

0

This is a partial answer I found by trial an error (well more of a desperate scatter gun approach) interestingly ensuring there were NO xdebug v2.6 directives in php.ini made no difference to the VSCode error. Failed loading C:\php\ext\php_xdebug-2.6.1-7.2-vc15-nts-x86_64.dll I copied numerous examples of launch.json I found on the web making sure the port and path to php matched php.ini. this launch.json version seemed to eliminate the misleading php7.2 error. (I have not got php7.2 anywhere) I am guessing that if the path to php.exe (which also needs to be set in settings.json is wrong VSCode has some fallback assumption about which PHP ver yoou are using

            "type": "php",
            "request": "launch",
            "runtimeExecutable": "C:/pathtophpexe/php.exe",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003
        }

After this I started getting a 'port' error Invalid "xdebug.client_port" setting. Invalid quantity "${port}": no valid leading digits

this latter problem was solved accidentally by replacing the php.ini line xdebug.client_host = 127.0.0.1

with xdebug.client_host = localhost

the xdebug.log was saying it couldnt connect to the port and therefore wouldn't step through of course

anyway replacing 127.0.0.1 with localhost in php.ini has cured the problem.

So though the primary objective has been achieved viz - getting debug to work I am non the wiser about where the php7.2 error came from (it seems to have nothing to do with xdebug version 2.6 directives)
nor why specifying 127.0.0.1 does not work whereas localhost does.

if you can shed light and want to comment please read and understand the essence of the question 'why does VSCode report and error about PHP v7.2 and xdebug 2.6 when neither are installed?' and secondly 'why is specifying localhost successful when 127.0.0.1 is not?'

oh and tx PaulT that site you suggested was one I'd come across in my scatter gun approach of trying all kinds of examples of launch.json. Interestingly it says it is 'essential; to include the line xdebug.idekey=VSCODE I have found that not to be the case (it doesnt matter whether its in php.ini or not but then Im only doing simple cli debugging - in any case the default is vsc and it can be found here

in VSCode under File > Preference > Settings > Extensions > PHP Debug > Ide Key.

I'm sorry that's not a complete explanation but it may help someone else cheers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.