xdebug를 사용하여 vscode에서 PHP 디버깅

환경: window10 + phpstudy

첫 번째 단계(큰 구덩이) : 사용 중인 PHP를 환경 변수에 추가합니다. phpstudy는 기본적으로 환경변수에 php를 추가하지 않고, 인터넷의 각종 글에도 이 단계에 대한 언급이 없기 때문에 결과적으로는 어떻게 구성을 작성해도 실패할 수밖에 없고, 오류 메시지도 나오지 않습니다. 나는 이 함정에서 2시간을 보낸 후에 이것을 발견했습니다.

 2단계: phpstudy에서 xdebug 확장 활성화

 3단계: php.ini를 열고 구성 수정

[Xdebug]

zend_extension=D:/phpstudy_pro/Extensions/php/php7.3.4nts/ext/php_xdebug.dll
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.auto_trace=On
xdebug.trace_output_dir=D:/phpstudy_pro/Extensions/php_log/php7.3.4nts.xdebug.trace
xdebug.profiler_enable=On
xdebug.profiler_output_dir=D:/phpstudy_pro/Extensions/php_log/php7.3.4nts.xdebug.profiler
xdebug.remote_enable=On
xdebug.remote_autostart = On 
xdebug.remote_host=localhost
xdebug.remote_port=9001
xdebug.remote_handler=dbgp

포트 9000을 사용하지 않는 것이 가장 좋습니다. 그렇지 않으면 Nginx와 충돌합니다.

세 번째 단계는 vscode 구성을 수정하는 것입니다.

파일 > 환경 설정 > 설정

 열린 settings.json에서 PHP 경로를 추가하십시오.

"php.debug.executablePath": "D:\\phpstudy_pro\\Extensions\\php\\php7.3.4nts\\php.exe",
"php.validate.executablePath": "D:\\phpstudy_pro\\Extensions\\php\\php7.3.4nts\\php.exe"

4부: 관련 플러그인 설치

 

다섯 번째 단계는 launch.json을 구성하는 것입니다. 포트 번호는 php.ini의 포트 번호와 일치해야 합니다.

{
    "configurations": [
        {
            "name": "Launch current script in console",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "externalConsole": false,
            "port": 9001
        },
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9001
        }
    
    ]
}

 그런 다음 디버깅을 활성화하고 액세스하십시오.

 

추천

출처blog.csdn.net/baidu_36095053/article/details/128019736