VS Code PHP 설정 방법

2020. 6. 4. 11:52Visual Studio

---- PHP 설치 후 VS Code 설정 내용 ----

* PHP는 "D:/WebServer/PHP" 에 설치 되어 있음.

1. 기본 설정

VS Code의 PHP 설정 파일을 열어줌.

1. File -> Preferences -> Settings (단축키: Ctrl + ,)

2. Extensions의 PHP 선택

3. Edit in settings.json 선택

settings.json 에서 설치된 PHP 경로를 설정

"php.validate.enable": false,
"php.validate.executablePath": "D:/WebServer/PHP/php.exe",

php.validate.enable 을 false로 둔 이유는 PHP IntelliSense 을 설치 할텐데, 여기서 기본 내장된 기능을 끄기를 권장함.

PHP IntelliSense 설치.

 

 

2. Debuging 설정

XDebug 설치하기

1. https://xdebug.org/wizard 접속 (가이드가 주소에 나와있음)

2. cmd 창에서 "php -i" 입력하면 phpinfo 가 주루룩 나옴. 긁어다가 사이트에 복사.

3. 하단의 *Analysis my phpinfo() output *클릭

4. dll 다운 받아서 php가 설치된 폴더의 ext에 dll을 이동 ("D:\WebServer\PHP\ext")

5. php.ini 파일 젤 하단에 아래 내용 추가.(php.ini 파일은 C:\Windows 안에 넣어두었었음)

zend_extension = D:\WebServer\PHP\ext\php_xdebug-2.9.6-7.4-vc15-x86_64.dll

6. cmd 창에 "php -m" 입력하여 [PHP Modules][Zend Modules]에 Xdebug 있는지 확인

7. php.ini 파일에 아래 내용 추가.

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

8. phpinfo()에 xdebug 상태 확인

9. PHP Debug 설치

10. Debug 탭에서 "create a launch.json file" -> "PHP" 선택

11. launch.json 파일 설정 (포트는 기본 9000, 변경시 php.ini 파일에 "xdebug.remote_port = 9090" 변경시켜줘야함)

12. 디버깅시 php.exe 파일을 못찾는 에러가 떠서 각 디버깅 별로 "runtimeExecutable": "

D:/WebServer/PHP/php.exe" 추가해줌.

{
    // 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",
            "runtimeExecutable": "D:/WebServer/PHP/php.exe",
            "request": "launch",
            "port": 9090
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "runtimeExecutable": "D:/WebServer/PHP/php.exe",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9090
        },
        {
            "name": "Launch Index",
            "type": "php",
            "runtimeExecutable": "D:/WebServer/PHP/php.exe",
            "request": "launch",
            "program": "${workspaceRoot}/index.php",
            "cwd": "${workspaceRoot}",
            "port": 9090
        }
    ]
}

'Visual Studio' 카테고리의 다른 글

Windows SDK 버전 문제  (0) 2020.02.12