XAMPP版本 v3.3.0 Compiled:Apr 6th 2021

首先(以下内容基于已经安装完成)

1.点击Apache的config 打开httpd.conf
2.找到DocumentRoot和Directory[使用ctrl+f搜索]
3.把他修改为你自己的web目录
比如我的是D:/webtest/test
虽然可以用其他方法做到多项目 但是我懒 反正平时就一个ww

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
DocumentRoot "D:\webtest\test"
<Directory "D:\webtest\test">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All

#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>

4.然后vscode定位到D:/webtest/test
5.用vscode新建一个index.html 和 form.php

/webtest/test/index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="./form.php" method="get"> //创建form 并且绑定index.html目录下的form.php [!方法为GET!]
昵称 <input type="text" name="username" id=""> //创建text input 输入文字 并且把变量设置为username
<br/> //换行
<button type="submit">提交</button> //确定内容 将username的text提交到后端php里的username变量

</form>
</body>
</html>
/webtest/test/form.php
1
2
3
4
<?php
$username = $_GET["username"]; //使用 !GET方法!获取到username
echo "ID: ".$username //输出username
?>

6.start Apache
7.在浏览器里输入localhost/index.html
8.enjoy