PHP8 + php_xdebug-3.x + Visual Studio Code Debugging > Web/PHP/API

본문 바로가기
사이트 내 전체검색

Web/PHP/API

PHP8 + php_xdebug-3.x + Visual Studio Code Debugging

페이지 정보

작성자 sbLAB 댓글 0건 조회 3,590회 작성일 22-12-07 19:08

본문

PHP8 + php_xdebug-3.x + Visual Studio Code Debugging  


1)  phpinfo.php 파일로 서버에 설치된 phpinfo 페이지 로드 -> 로드화면 전체복사(CTRL+A)


<?php
phpinfo();
?> 


https://xdebug.org/wizard.php    <-  이곳에 붙혀넣기 해서 분석 후 제안되는 php_xdebug-3.1.6-8.1-vs16-x86_64.dll  다운로드

 -> apm서버 php확장라이브러리 폴더에 다운 받은 dll 복사 ex) D:/xampp/php/ext 에  dll 복사


2) php.ini 설정

D:/xampp/php/php.ini  수정, 맨 아래에 아래내용 추가


[XDebug] 

zend_extension = D:/xampp/php/ext/php_xdebug-3.1.6-8.1-vs16-x86_64.dll

xdebug.mode=debug

xdebug.start_with_request=yes

xdebug.client_port=9003


[참고] Xdebug 2 에서 Xdebug 3 으로 버전업 되면서 설정파라미터가 변경됨

(상세정보는 https://xdebug.org/docs/upgrade_guide  )


[참고] Xdebug 작동시 APM 매우 느려짐(실제 서비스할때는 php.ini 에서 Xdebug 부분 주석처리 또는 제거)

(Xdebug 비활성화시 페이지로드 : 7ms 속도 빠름)

1a926a1e5f89e11ebd89fb3d0f3c25b0_1670605064_0782.jpg

(Xdebug 활성화시 페이지로드 : 410ms 속도 매우느림)
1a926a1e5f89e11ebd89fb3d0f3c25b0_1670605067_756.jpg



3) 웹서버(Apache) 재시작


4)  Visual Studio Code 설치 https://code.visualstudio.com/ 
  Visual Studsio Code 실행시 관리지모드로 실행(아이콘에서 관리지권한 실행 속성설정필요) 


5)  Visual Studio Code 에서 php 관련 주요 플러그인 설치


PHP Debug v1.29.0

PHP Intelephense v1.8.2 설치
위에서 설치한 PHP Intelephense 와 Vcode 툴의 기본 PHP Language Features. 플러그인이 중복되므로 

(PHP Language Features 비활성화(disable), PHP Language Basics는 활성화(enabled))


Disable the built-in VSCode PHP Language Features.

  • Go to Extensions.
  • Search for @builtin php
  • Disable PHP Language Features.    PHP Language Basics 은 남김(enabled) for syntax highlighting.
  • 478737e41a3da98c38cb1c0d67600919_1670454306_1243.jpg

    그밖에 기타 플러그인 설치(선택)
  • Material Icon Theme  <- 아이콘테마(깔끔)
  • Doxygen Documentation  <- /** 주석자동생성(파라미터, 리턴값) 
  • Project Manager <- 각 프로젝트 빠른 이동


478737e41a3da98c38cb1c0d67600919_1670408298_3911.jpg
 

6) Visual Studio Code 에 PHP 디버깅 세팅

launch.json 파일생성 (아래 메뉴 클릭시 자동생성 됨)

478737e41a3da98c38cb1c0d67600919_1670408545_3642.jpg
 

아래 launch.json 파일 내용 확인  <- 웹서버 php.ini 에서 설정(xdebug.client_port=9003)한 9003 포트 번호로 수정


{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003,
            "runtimeArgs": [
                "-dxdebug.start_with_request=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug,develop",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },
        {
            "name": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.start_with_request=yes",
                "-S",
                "localhost:0"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9003,
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        }
    ]
}



[Settings.json] 

File - Preferences - Settings - Extension - PHP Debug - Edit in Settings.json 클릭, 아래처럼 수정 (php.exe 경로 설정)

settings.json 파일 위치 => C:/Users/[accountname]/AppData/Roaming/Code/User/settings.json

{
    "php.validate.executablePath": "D:/xampp/php/php.exe",
    "php.executablePath": "",
    "php.debug.executablePath": "D:/xampp/php/php.exe",
    "editor.lineHeight": 1.4,
    "editor.fontSize": 15,
    "editor.mouseWheelZoom": true,
    "workbench.iconTheme": "material-icon-theme"
}



7) 웹서버 웹루트에 아래 pc.php 테스트파일 생성

D:/xampp/htdocs/pc.php


[pc.php 테스트 파일]

<?php
for($i = 0 ; $i < 5 ; $i ++) {
    print("num : ${i} </br>");
};
?>

 




8) Visual Studio Code 에서 작업소스(php) 디버깅 포인트 찍어주고  Listen for Xdebug (F5)  시작


478737e41a3da98c38cb1c0d67600919_1670409670_4814.jpg



9) 크롬에서 Xdebug helper 확장프로그램 설치 

https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc 


Xdebug 확장프로그램 Debug 활성화


478737e41a3da98c38cb1c0d67600919_1670409233_3985.jpg


10) 크롬 브라우저에서  http://localhost/pc.php 접속하여 디버깅 시작


아래처럼 알수없는 명령어에 대한 에러 표시, 변수 값 디버깅 모두 가능.

(크롬부라우저에서 php 실행하며 디버깅 + 오류정보를 Visual Code 디버깅 리스너에 전달하는 구조 : 크롬 Xdebug <=> PHP Debug 플러그인)


478737e41a3da98c38cb1c0d67600919_1670410049_3506.jpg
 

크롬 웹접근 필요없이 자체 로직 실행가능한 로직 테스트 php 파일인 경우는

아래 이미지 Launch currently open script  또는 디버깅 아이콘으로 바로 디버깅 시작.


478737e41a3da98c38cb1c0d67600919_1670410811_0704.jpg
 

11) 기타 에디터 환경설정(선택)

[줄간격] File -> Preferences -> Settings -> search 'line' -> Line Height : 1.3

[폰트]  File -> Preferences -> Settings -> Text Editor -> Font(Font Family) : Consolas, 'Courier New', monospace


댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
140
어제
433
최대
1,279
전체
218,808

그누보드5
Copyright © sebom.com All rights reserved.