![](/img/trans.png)
[英]How to use Xdebug in Visual Studio Code to debug PHP Scripts in Ubuntu for Xampp
[英]How can I debug PHP Laravel on Visual Studio Code without use XAMPP or WAMP server
我在 Laravel 5.7 中使用 PHP 7.3.1。
如何在不安装外部服务器的情况下逐步进行调试? 使用 Xdebug?
只需运行以下命令:
php artisan serve
然后我创建的所有解决方案都使用 WAMP。
根据您的 PHP 版本在 php.ini 文件中设置 xdebug 扩展。
在此处检查哪个版本的 xdebug 支持您的 PHP: https ://xdebug.org/wizard.php
不要忘记更改您的 xdebug 扩展路径zend_extension
。
还将 xdebug 扩展添加到浏览器中。 对于 mozila,请单击此处。
[xdebug]
zend_extension = "C:\php\ext\php_xdebug-2.7.0-7.2-vc15.dll"
xdebug.remote_autostart = 1
;xdebug.profiler_append = 0
;xdebug.profiler_enable = 0
;xdebug.profiler_enable_trigger = 0
;xdebug.profiler_output_dir = "c:\xampp\tmp"
;xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
;xdebug.remote_handler = "dbgp"
;xdebug.remote_host = "127.0.0.1"
;xdebug.remote_log = "c:\xampp\tmp\xdebug.txt"
;xdebug.remote_port = 9000
;xdebug.trace_output_dir = "c:\xampp\tmp"
;36000 = 10h
;xdebug.remote_cookie_expire_time = 36000
;xdebug.trace_output_dir = "C:\xampp\tmp"
我会尝试使用 Xdebug 启动工匠,例如php -z /path/to/xdebug.so artisan serve
。
然后使用 Visual Studio 代码的PHP 调试扩展来设置断点、检查变量和所有其他调试内容。
在项目的.vscode
目录中创建一个launch.json
以下内容的launch.json
文件对我.vscode
:
{
// 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
}
]
}
终于完成了我的开发环境的设置,过程如下:
使用 Homestead/Vagrant/VirtualBox 虚拟环境和 VSCode Debug 插件
编辑或在第一个F5 之后, .vscode/launch.json
将使用如下设置创建:
//file: .vscode/launch.json "version": "0.2.0", "configurations": [ { "name": "Listen for Xdebug", "type": "php", "request": "launch", "port": 9003 }, // ...
# sudo vim /etc/php/8.1/fpm/php.ini zend_extension=xdebug.so xdebug.mode = debug xdebug.discover_client_host = true xdebug.client_port = 9003 xdebug.max_nesting_level = 512 xdebug.idekey = VSCODE xdebug.start_with_request=yes xdebug.client_host=10.0.2.15 # <--- my Homestead/Vagrant/VirtualBox IP address (ip addr show)
sudo service php8.1-fpm restart
php artisan serve
- 将部署/发布/附加 php 代码到php8.1-fpm
服务
Ubuntu 21.10
vagrant ssh-config
复制粘贴到~/.ssh/config
php artisan serve
- 从 shell 运行以将 php 文件部署/发布/附加到php8.1-fpm
php \\ -dzend_extension=xdebug.so \\ -dxdebug.mode=debug \\ -dxdebug.discover_client_host=true \\ -dxdebug.client_port=9003 \\ -dxdebug.max_nesting_level=512 \\ -dxdebug.idekey=VSCODE \\ -dxdebug.start_with_request=yes \\ -dxdebug.client_host=10.0.2.15 \\ artisan serve
artisan
脚本的某处php artisan serve
替换service php8.1-fpm status
- 在后台运行
xdebug.ini
文件应配置如下: zend_extension=xdebug.so xdebug.mode = debug xdebug.discover_client_host = true xdebug.client_port = 9003 xdebug.max_nesting_level = 512 xdebug.idekey = VSCODE xdebug.start_with_request=yes xdebug.client_host=10.0.2.15
/etc/php/8.1/mods-available/xdebug.ini
后始终执行sudo service php8.1-fpm restart
SomeCustomController.php
文件中的某处放置刹车点./vscode/launch.json
和上面的 php部分将能够通过端口9003
与其通信可能有多个
php.ini
文件。 在许多设置中,命令行(通常是cli/php.ini
)和 Web 服务器(通常是fpm/php.ini
)有不同的设置
php-fpm8.1 -m
- 列出php --ini
和php -v
- 未列出且不需要 XDebug
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.