跟着别人学习的PHP,在学习的过程中需要我们安装wampserver的套件。安装好了过后,需要简单的改变网站的根目录,这里简单的介绍一下在配置跟目录时,遇到坑。
1.自定义网站根目录
(1).www根目录的配置
默认的Apache根目录在wampserver安装目录中www目录,但是如果我们修改它的话,就必须进行配置。
可能在之前的wampserver版本中,直接配置httpd.conf文件就行。但是如果使用的是比较新的版本的话,比如说,我使用的是Apache 2.4.27,只配置一个文件的话,打开网站直接报404。(我在wampserver安装目录下新建了一个demo文件夹)
A.httpd.conf
DocumentRoot "${INSTALL_DIR}/www" => DocumentRoot "${INSTALL_DIR}/demo"
<Directory "${INSTALL_DIR}/www"> => <Directory "${INSTALL_DIR}/demo">
B.httpd-vhosts.conf
DocumentRoot "${INSTALL_DIR}./www" => DocumentRoot "${INSTALL_DIR}./demo" //记得}和/之间有一个‘.’符号。
<Directory "${INSTALL_DIR}./www"> => <Directory "${INSTALL_DIR}./demo">
经过上面的两个文件配置,我们重启全部服务,然后就可以访问得到了。
(2).多站点的配置
经过上面的配置,我们虽然可以正确的打开网页,但是www目录的指向还是没变的,因此还需要我们去更改配置。
A.wampmanager.ini
Type: item; Caption: "www directory"; Action: shellexecute; FileName:
"E:/Application/php/wampserver/wamp64"; Glyph: 2 改为 Type: item; Caption: "demo directory"; Action:
shellexecute; FileName: "E:/Application/php/wampserver/wamp64/demo"; Glyph: 2
B.wampmanager.tpl
Type: item; Caption: "${w_wwwDirectory}"; Action: shellexecute; FileName: "${wwwDir}"; Glyph: 2 改为 Type: item; Caption: "www directory"; Action: shellexecute; FileName: "E:/Application/php/wampserver/wamp64/demo"; Glyph: 2
最后记得将程序退出,一定要退出!再进去就对了。
2.wampserver多站点配置
通常我们还会在同一个端口对应多个域名,这个怎么办?
(1).httpd-vhosts.conf
首先,我们得在这个文件中新增加站点。
<VirtualHost *:80>
ServerName test01.com
# ServerAlias localhost
DocumentRoot "${INSTALL_DIR}./demo/test01"
<Directory "${INSTALL_DIR}./demo/test01">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName test02.com
# ServerAlias localhost
DocumentRoot "${INSTALL_DIR}./demo/test02"
<Directory "${INSTALL_DIR}./demo/test02">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
如果想要其他都能访问我们的站点的话,必须将Require local改为Require all granted。同时在httpd.conf文件中也需要更改这个权限,那个权限在<Directory "{INSTALL_DIR}/www">)。
(2).改变系统的hosts文件
hosts文件的地址:C:\Windows\System32\drivers\etc,我们需要在hosts文件末尾增加两条记录:
127.0.0.1 test01.com
127.0.0.1 test02.com
但是我们发现在我们尽管能够修改,但是不能保存,教程:Win10修改编辑hosts文件无法保存怎么办
(3).编写网站代码
记得在demo文件夹中,新建两个文件夹test01、test02,然后再分别在两个文件夹中新建php文件就行。