XAMPP和VScode 实现对PHP的编写和调试,xamppvscode
XAMPP和VScode 实现对PHP的编写和调试,xamppvscode
在工作中遇到了需要开发PHP的情况,因为习惯用VS开发.net系列,所以决定用VScode继续开发PHP。对搭建VSCode的开发环境的过程做了一些总结。
Xmapp的安装
下载并且安装合适自己电脑的XMAPP的版本。下载地址:https://www.apachefriends.org/zh_cn/download.html
我用的是(7.0.27 / PHP 7.0.27)Window32位版本。
xDebug的安装
首先运行XMAPP以后,发现已经监听了80端口
打开浏览器访问 Http://localhost/,然后查看PHPInfo,找到正确的PHP版本,特别是是否线程安全。因为这个版本决定了Xdebug的版本,如果版本寻找不对,XDEBUG是无法安装成功的。
下载PHP对应的XDebug版本。下载地址:https://xdebug.org/download.php ,解压以后修改dll名称为php_xdebug.dll, 复制到php的ext文件夹下面。
修改php.ini,在下面增加
[XDebug]
zend_extension = "php_xdebug.dll"
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "C:/xampp/tmp"
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9010
xdebug.remote_connect_back=0
xdebug.remote_enable = 1
xdebug.remote_autostart=1
xdebug.idekey=netbeans
特别需要注意的是remoting_port的设置,跟后面vscode需要一致。我再配置xdebug的时候,因为版本问题,走了很多弯路。
配置Apache的虚拟目录
首先在Apache的httpd.conf中把 #Include conf/extra/httpd-vhosts.conf修改为Include conf/extra/httpd-vhosts.conf。
然后找到httpd-vhosts.conf,在后面增加下面代码
<VirtualHost *:9000>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "D:/Learn/Spider/"
ServerName localhost
ErrorLog "logs/spider"
CustomLog "logs/dspider" common
</VirtualHost>
重启apache服务,访问localhost:9000,会发现提示没有权限访问。然后再httpd-vhosts.conf文件中增加下面片段,并且重启Apache服务。
<Directory "D:/Learn/Spider/">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
访问localhost:9000访问正常。
下载并且安装VScode
按照微软的惯例,一路NEXT就完成了安装,下载地址:https://code.visualstudio.com/
配置VSCode的PHP开发环境
1. 在VSCode的扩展中输入ext:php,安装PHP debug。
2. 在文件=》首选项=》设置
{
"php.validate.executablePath":"C:/xampp/php/PHP.exe"
}
3.可以建立和浏览刚刚设置的项目。设置Lauch.json如下
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9010 //刚刚xdebug设置的端口
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
可以点击VS的调试,打开浏览器浏览http://localhost:9000/,进行断点调试。
相关文章
- 暂无相关文章
用户点评