Xdebug + VSCode + PHP + WampServer :调试会话开始时未命中断点
Xdebug + VSCode + PHP + WampServer : breakpoint not hit on start of debug session
前段时间我成功解决了这个问题:
现在我有 PHP 8 和最新的 VSCode 和 Xdebug 3,但是我的 API 中没有命中断点,它使用从 [重命名的自定义主机名运行=17=](虚拟主机)在 Node.js ReactJS 应用程序的后面(在 riskaim:3000
,其中 PHP API 服务器是 运行 在 riskaim:9003
)
我无法让 VSCode 调试器在我设置了断点的行上停止。
我该如何解决这个问题?
这是我的设置:
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
}
]
}
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>
原来我在 api 文件夹的 .htaccess
文件中添加了一个不必要的行。删除此行解决了问题,调试器步骤光标开始成功工作。
所做的更改
.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= [L,QSA]
ErrorDocument 403 "<meta http-equiv='refresh' content='0; url=//riskaim:3000' />"
ErrorDocument 404 "<meta http-equiv='refresh' content='0; url=//riskaim:3000' />"
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 文件中间
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>
前段时间我成功解决了这个问题:
现在我有 PHP 8 和最新的 VSCode 和 Xdebug 3,但是我的 API 中没有命中断点,它使用从 [重命名的自定义主机名运行=17=](虚拟主机)在 Node.js ReactJS 应用程序的后面(在 riskaim:3000
,其中 PHP API 服务器是 运行 在 riskaim:9003
)
我无法让 VSCode 调试器在我设置了断点的行上停止。
我该如何解决这个问题?
这是我的设置:
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
}
]
}
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>
原来我在 api 文件夹的 .htaccess
文件中添加了一个不必要的行。删除此行解决了问题,调试器步骤光标开始成功工作。
所做的更改
.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= [L,QSA]
ErrorDocument 403 "<meta http-equiv='refresh' content='0; url=//riskaim:3000' />"
ErrorDocument 404 "<meta http-equiv='refresh' content='0; url=//riskaim:3000' />"
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 文件中间
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>