Cách cài đặt Debug PHP trong Visual Studio Code

Cách cài đặt Debug PHP trong Visual Studio Code

Điều kiện đã cài đặt các tool sau:
1. Cài đặt Xampp, hoặc Laragon, hoặc bất kỳ Server run PHP nào
2. Visual Studio Code
3. Cài đặt extention PHP Debug cho Visual Studio Code

Nhớ setting php.validate.executablePath = “Đường dẫn đến file php.exe trong xampp hoặc laragon”
(File / Preferences / Setting)

Cài đặt PHP Debug

  1. Tạo file show thông tin cấu hình của php.
    Ở đây mình tạo file index.php đặt trong htdocs với xampp, hoặc www với laragon
    copy đoạn code sau vào file index.php vừa tạo
<?php
phpinfo();

2. Ra ngoài trình duyệt truy cập file vừa tạo ở trên

http://localhost/index.php

kết quả ở trình duyệt

3. Thực hiện copy nội dung ở trên: Ctrl + A -> Ctrl + C

4. Truy cập site: https://xdebug.org/wizard

Sau đó Paste vào ô text trên site, kết quả như sau:

Sau đó click vào button Analyse my phpinfo() output

Kết quả ra được các bước hướng dẫn cài đặt debug

Làm hết bước 3 bổ sung thêm line code sau vào cuối file php.ini

[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1

Bước 4 restart lại xampp hoặc laragon. Sau đó bật Visual Studio Code lên thử thành quả.

Chú ý với XDebug version 3.0 cần config như sau:

[XDebug]
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.remote_enable = 1
xdebug.remote_autostart = 1

Post a comment

Your email address will not be published.