[컴][php] vscode 에서 php debugging 환경 설정

visual studio code 에서 php 디버깅 환경 설정 / 비쥬얼 스튜디오 코드에서 php debug 환경설정

update: 20025-07-15

vscode 에서 php debugging 환경 설정

vscode 가 설치되어 있는 상태여야 한다.

PHP Debug extension 설치 : extension 설치
여기서 php root directory 는 "c:\a\apps\php-7.1.4-x64" 이다.

XDebug 설치

  • .dll download : Xdebug: Downloads

  • php의 ext 에 .dll 옮겨넣기

    c:\a\apps\php-7.1.4-x64\ext\php_xdebug-2.5.3-7.1-vc14-x86_64.dll

php가 XDebug 를 사용하게 설정

  • c:\a\apps\php-7.1.4-x64\php.ini 에 아래 사항 추가

    zend_extension = php_xdebug-2.5.3-7.1-vc14-x86_64.dll
    extension_dir = "C:/a/apps/php-7.1.4-x64/ext"

XDebug 의 remote debug 설정 on

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

; xdebug 3 에서는 아래처럼 세팅하면 된다.
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9003
xdebug.client_host = "127.0.0.1"
xdebug.log = "C:\a\tmp\xdebug\xdebug.log"
xdebug.idekey = VSCODE

php test.php 를 하면 output 에서 xdebug 설정을 확인할 수 있다.

vscode 에서 php debugger 실행

PHP Debug extension 설치

XDebug 설치

.dll download : Xdebug: Downloads
아래 경로로 .dll 옮겨넣기

  • c:\a\apps\php-7.1.4-x64\ext\php_xdebug-2.5.3-7.1-vc14-x86_64.dll

php가 XDebug 를 사용하게 설정
c:\a\apps\php-7.1.4-x64\php.ini 에 아래 사항 추가

extension_dir = "c:/a/apps/php/php-7.1.4-x64/ext"
zend_extension = php_xdebug-2.5.3-7.1-vc14-x86_64.dll

XDebug 의 remote debug 설정 on

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

php test.php 를 하면 output 에서 xdebug 설정을 확인할 수 있다.
test.php

<?php
phpinfo();
?>



vscode 에서 preference: open user settings

// Place your settings in this file to overwrite the default settings
{
    "php.validate.executablePath": "c:/a/apps/php-7.1.4-x64/php.exe"


}

vscode 에서 debugger 실행

launch.json 는 다음과 같다.

먼저 debugger를 실행해 놓고, php artisan serve 로 test server를 실행해도 된다.

{
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        },
    ]
}

Test

c:\Program Files\Apache\Apache24 에 apache 를 설치했다고 하자. 그리고 htdocs 가 root 라고하자.


이 상황에서 apache 를 실행하고,

vscode 로 아래 path 의 folder 를 열고

  • c:\Program Files\Apache\Apache24\htdocs\

test.php 에 breakpoint 를 걸어놓는다.

"Listen for XDebug" 로 실행

browser 에서 "localhost:8080/test.php" 로 가면,

breakpoint 에서 멈춘다.

debugger 가 동작하지 않는 경우

혹시나 breakpoint 가 잡히지 않는 경우 php.ini 의 xdebug 설정 문제 일 수 있다.

See Also

References

  1. PHP Programming with Visual Studio Code
  2. PHP Debug - Visual Studio Marketplace




댓글 3개:

  1. 저기요 a가 뭘 의미하나요?

    답글삭제
  2. 파일 경로 c:\a\apps\php-7.1.4-x64\ext\php_xdebug-2.5.3-7.1-vc14-x86_64.dll
    a는 무얼 의미하나요 a 없는데 하나 만들으란 소린가요 ? //..

    답글삭제
    답글
    1. "c:\a\apps\php-7.1.4-x64" 는 php 가 설치된 path 입니다.
      본문을 수정했습니다.

      삭제