
Visual Studio Code + PHP Xdebug
PHPWindow 환경에서 Visual Studio Code 로 PHP 디버깅하기
+ 하는 김에 Apache 설치
1. PHP Download
Link: https://windows.php.net/download/
PHP는 Multi-Process를 지원하는 언어
Thred Safe(TS): Multi-Thread
Non Thread Safe(NTS): Single Thread\
Window bit에 맞는 Zip 파일 다운로드
2. Apache Download
Link: https://www.apachelounge.com/download/
Window bit에 맞는 Zip 파일 다운로드
3. 압축 풀기
실행 파일 위치를 지정하여 해당 폴더에 압축 풀기
D:\apache-2.4
D:\php-7.4
4. Apache Setting
1) httpd.conf 수정
Plain Text
# Modify
Define SRVROOT "D:/apache-2.4/Apache24"
# ADD
ServerName localhost
2) 관리자 권한으로 CMD 실행
3) 설치 및 실행
Plain Text
> D:\apache-2.4\Apache24\bin\httpd.exe -k install
Installing the 'Apache2.4' service
The 'Apache2.4' service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
4) httpd.conf 문법 검사
Plain Text
> D:\apache-2.4\Apache24\bin\httpd.exe -n "Apache2.4" -t
5) 구동
Win+Q: Services.msc 열기
Apache2.4 서비스 시작 실행

* 제거
Plain Text
> D:\apache-2.4\Apache24\bin\httpd.exe -k shutdown
> D:\apache-2.4\Apache24\bin\httpd.exe -k stop
> D:\apache-2.4\Apache24\bin\httpd.exe -k uninstall
5. PHP Setting
1) php.ini 생성
php.ini-development 내용 중 extension 폴더 경로를 수정하여 ini 생성
Plain Text
# ADD
extension_dir = "D:\php-7.4\ext"
2) httpd.conf 수정
Plain Text
# ADD
include conf.d/*.conf
3) /Apache24/conf.d/php.conf 파일 생성
Plain Text
# ini 위치
PHPInidir "D:/php-7.4"
# php7apache2_4.dll 지정
LoadModule php7_module "D:/php-7.4/php7apache2_4.dll"
AddType application/x-httpd-php .html .php
<ifModule dir_module>
DirectoryIndex index.php
</ifModule>
4) Apache 재시작
Plain Text
> D:\apache-2.4\Apache24\bin\httpd.exe -k restart
6. localhost 확인

7. index.php 확인
Apache htdocs 폴더에 index.php 생성
PHP
<?php
phpinfo();
?>
8. localhost 확인

9. Visual Studio Code 확장 설치
PHP IntelliSense
PHP Debug
10. setting.json 파일에 php 설정
1) Ctrl + ,
2) php setting
3) setting.json
JSON
"php.validate.executablePath": "D:/Dev/work/Library/php-7.4/php.exe"
11. launch.json 설정
Ctrl + Shift + D
JSON
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Program",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html": "${workspaceRoot}/www",
"/app": "${workspaceRoot}/app"
}
}
]
}
12. Xdebug Install
참고 Link: https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug
Link: https://xdebug.org/wizard
1) phpinfo() 내용을 전체 복사 붙여넣기 => Analyse my phpinfo() output => 권장하는 dll 파일 다운로드
2) php-7.4/ext 에 dll 파일 삽입
3) php.ini 내용 추가
Plain Text
[XDebug]
zend_extension = "D:\php-7.4\ext\php_xdebug-2.9.6-7.4-vc15-x86_64.dll"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
13. Apache 재시작 후 phpinfo() 확인
Plain Text
> D:\apache-2.4\Apache24\bin\httpd.exe -k restart

14. Visual Studio Code 에서 PHP 디버깅 (F5)
