Home > Software design >  Xdebug VSCode PHP WampServer : breakpoint not hit on start of debug session
Xdebug VSCode PHP WampServer : breakpoint not hit on start of debug session

Time:04-30

A while back I succeeded at resolving this problem:

How to properly setup VSCode and Wampserver to be able to debug and pause on breakpoint line, using VSCode / PHP XDebug / PHP Debug Extension?

Now I have PHP 8 with the latest VSCode and Xdebug 3, but my breakpoint is not hit in my API, which runs with a custom host name renamed from localhost (virtual host) in back of a Node.js ReactJS app (on riskaim:3000, where as the PHP API server is running on riskaim:9003)

I can't get the VSCode debugger to stop on the line on which I have set a breakpoint.

How do I resolve this?

Here are my settings:

Bottom of php.ini c:/wamp64/bin/apache/php/apache2.4.46/bin/php.ini

; XDEBUG Extension
[xdebug]
zend_extension="c:/wamp64/bin/php/php8.0.9/ext/php_xdebug-3.0.4-8.0-vs16-x86_64.dll"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_mode = "req" 
xdebug.mode = debug       
xdebug.client_port = "9003"
xdebug.remote_log = "c:/wamp64/tmp/log"
xdebug.show_local_vars = 0
xdebug.idekey = vsc

settings.json

{
    "php.executablePath": "C:/wamp64/bin/php/php8.0.9/php.exe",
}

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": 9003
            }
        ]
    }

Middle of httpd.conf

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 9003

httpd-vhosts.conf

# Virtual Hosts
#

<VirtualHost *:9003>
  ServerName localhost
  DocumentRoot "${INSTALL_DIR}/www/"
  <Directory "${INSTALL_DIR}/www/">
    Options  Indexes  Includes  FollowSymLinks  MultiViews
    AllowOverride All
    Require local
  </Directory>
</VirtualHost>




<VirtualHost *:9003>
    ServerName riskaim
    DocumentRoot "${INSTALL_DIR}/www/RiskAIM/"
    <Directory  "${INSTALL_DIR}/www/RiskAIM/">
        Options  Indexes  Includes  FollowSymLinks  MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

CodePudding user response:

It turns out I had added an unnecessary line in my .htaccess file of my api folder. Removal of this line fixed the problem and the debugger step cursor started working successfully.

Changes made

.htaccess

RewriteBase /
RewriteEngine On
Options -Indexes
DirectoryIndex api.php

RewriteCond %{REQUEST_URI} ^/api/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{SERVER_PORT}=80            <-------------- I removed this line and it the debugger started stepping through the code on my first api get request
RewriteRule ^(.*)$ /api/api.php?requestPath=$1 [L,QSA]

ErrorDocument 403  "<meta http-equiv='refresh' content='0; url=//riskaim:3000' />"
ErrorDocument 404  "<meta http-equiv='refresh' content='0; url=//riskaim:3000' />"

Bottom of php.ini (c:/wamp64/bin/apache/apache2.4.46/bin/php.ini)

   [xdebug]
    zend_extension="c:/wamp64/bin/php/php8.0.9/zend_ext/php_xdebug-3.0.4-8.0-vs16-x86_64.dll"
    xdebug.mode = develop,debug
    xdebug.start_with_request = yes
    xdebug.client_host = localhost
    xdebug.client_port = "9003"
    xdebug.idekey = vsc

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": "Launch Chrome",
                "request": "launch",
                "type": "chrome",
                "url": "http://riskaim:3000",
                "webRoot": "${workspaceFolder}"
            },      
            {
                "name": "Listen for Xdebug",
                "type": "php",
                "request": "launch",
                "port": 9003,
                "hostname": "riskaim",
                "pathMappings": {
                    "c:\\wamp64\\www\\riskaim": "${workspaceRoot}"
                }
            }
        ]
    }

httpd.conf Middle of file

Listen 80  <------------ changed from Listen 9003 (incorrect)

httpd-vhosts.conf

<VirtualHost *:80>   <----------------changed from *:9003
    ServerName riskaim
    DocumentRoot "${INSTALL_DIR}/www/RiskAIM/"
    <Directory  "${INSTALL_DIR}/www/RiskAIM/">
        Options  Indexes  Includes  FollowSymLinks  MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>
  • Related