VSCode调试PHP

1、安装PHP Debug

VSCode调试PHP_第1张图片

2、配置php.ini

[xdebug]
; zend_extension = D:\DEVTOOLS\PHP\php72\ext\php_xdebug-2.7.1-7.2-vc15-x86_64.dll
zend_extension = "D:\DEVTOOLS\PHP\php72\ext\php_xdebug-2.7.2-7.2-vc15-x86_64.dll"
xdebug.auto_trace=on
xdebug.collect_params=on
xdebug.collect_return=on
xdebug.trace_output_dir ="D:\DEVTOOLS\PHP\xdebug_log"
xdebug.profiler_output_dir ="D:\DEVTOOLS\PHP\xdebug_log"
xdebug.profiler_output_name = "cachegrind.out.%t.%p"
xdebug.remote_enable = on
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
# 设置端口号,默认是9000,此处因为本地环境端口冲突故设置为9001(在vscode配置中需要用到)
xdebug.remote_port = 9001
xdebug.remote_autostart=on
# 这是用于phpstorm中xdebug调试的配置,在vscode中没有用到
xdebug.idekey = phpstorm

 3、配置VSCode

文件->首选项->设置->扩展设置-PHP->右上角{},打开设置json

{
    "editor.fontSize": 16,
    "window.zoomLevel": 1,
    "php.validate.executablePath": "D:/DEVTOOLS/PHP/php72/php.exe",
    "php.validate.enable": false,
    "php.executablePath": "D:/DEVTOOLS/PHP/php72/php.exe",
    "code-runner.runInTerminal": true
}

调试->打开配置,端口9001与php.ini中的设置一致,9000为apache的端口

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [        
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9001
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9001
        }
    ]
}

4、Apache配置httpd.conf

#httpd.conf
Define SRVROOT "D:/DEVTOOLS/PHP/Apache/Apache24"

ServerRoot "${SRVROOT}"

Listen localhost:9000

LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule allowmethods_module modules/mod_allowmethods.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule include_module modules/mod_include.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
# 开启伪静态
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule ssl_module modules/mod_ssl.so
#apache virtualhost配置 apache配置多个网站
LoadModule vhost_alias_module modules/mod_vhost_alias.so

#php配置
PHPIniDir D:/DEVTOOLS/PHP/php72
LoadModule php7_module D:/DEVTOOLS/PHP/php72/php7apache2_4.dll


User daemon
Group daemon



ServerName localhost:9000

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
#  blocks below.
#

    # AllowOverride none
	AllowOverride All 
    Require all denied



    # AllowOverride None
	AllowOverride All
    Options None
    Require all granted
#httpd-vhosts.conf


Define WEBROOT_TP5 "E:/study/PHP/myproject/tp5/public"
Define WEBROOT_JQUERY "E:/study/JS/JQuery/FL_JQuery"

#修改物理主机hosts文件(C:\Windows\System32\drivers\etc),因为这里是因为物理机去访问Apache服务器
# 127.0.0.1 tp5.com
# 127.0.0.1 jquery.com

# http://tp5.com:9000/

    DocumentRoot "${WEBROOT_TP5}"
    ServerName tp5.com
	
		Options Indexes FollowSymLinks
		# AllowOverride None
		# 开启伪静态
		AllowOverride All
		Require all granted
	 


# http://jquery.com:9000/

    DocumentRoot "${WEBROOT_JQUERY}"
    ServerName jquery.com
	
		Options Indexes FollowSymLinks
		# AllowOverride None
		# 开启伪静态
		AllowOverride All
		Require all granted
	 

6、启动Apache下的httpd.exe, 

7、在VSCode中下断点,并启动调试

VSCode调试PHP_第2张图片

8、在chrome浏览器中输入http://tp5.com:9000/

9、进入断点调试

VSCode调试PHP_第3张图片

 

你可能感兴趣的:(PHP)