wamp环境安装thinkphp5.0-wamp环境配置vhosts

环境
windows7 , wampserver集成环境 , thinkphp5.0文件
wamp目录:D:/wamp/www
thinkphp目录:F:/tp5
thinkphp入口文件:F:/tp5/public/index.phpphp

第一步:修改http.conf文件,将http-vhosts.conf配置文件包含进来
点击wamp-apache-http.conf,用记事本打开,定位到此处。web

# Virtual hosts  
#Include conf/extra/httpd-vhosts.conf  
改成  
# Virtual hosts  
Include conf/extra/httpd-vhosts.conf

注意:不要去掉第一个#号,不然wamp没法正常运行thinkphp

第二步:配置http-vhosts.conf
点击wamp-apache-http-vhosts.conf,用记事本打开,全选粘贴如下内容。apache

# VirtualHost example:  
    # Almost any Apache directive may go into a VirtualHost container.  
    # The first VirtualHost section is used for all requests that do not  
    # match a ServerName or ServerAlias in any <VirtualHost> block.  
    #  
    <VirtualHost *:80>  
        ServerAdmin webmaster@dummy-host.example.com  
        DocumentRoot "D:\wamp\www"  
        ServerName localhost  
        ServerAlias www.dummy-host.example.com  
        ErrorLog "logs/localhost-error.log"  
        CustomLog "logs/localhost-access.log" common  
    </VirtualHost>  
      
    <VirtualHost *:80>  
        ServerAdmin webmaster@dummy-host2.example.com  
        DocumentRoot "F:\tp5\public"  
        ServerName tp5.com
        ErrorLog "logs/tp5.com-error.log"  
        CustomLog "logs/tp5.com-access.log" common  
        <Directory />  
            Require all granted  
        </Directory>  
    </VirtualHost>

在第一个例子中只改动了servername和documentRoot,这个配置保证了咱们在开启vhost后仍然能够访问www目录。
在第二个例子中,除了修改serverName和documentRoot之外,还添加了Directory那句话,若是不添加这句话,当咱们访问tp5.com的时候会报403权限的错误。windows

注意:浏览器

DocumentRoot "F:\tp5\public"  #填写入口文件所在的文件夹
        ServerName tp5.com            #用tp5.com来访问这个网站入口文件

第三步:修改C:\Windows\System32\drivers\etc\hosts文件
在最后一行加入thinkphp5

127.0.0.1 tp5.com

最后重启wamp,在浏览器输入tp5.com
若是看到这样的页面就成功了:)
图片描述网站

一键操做
点击wamp主页的Tool栏目下的Add a Virtual Host,能够帮助你一键添加vhost
可是访问wamp主页时页面出现以下警告(暂不清楚缘由):ui

The number of <Directory or </Directory> does not match the number of ServerName in d:/wamp/bin/apache/apache2.4.23/conf/extra/httpd-vhosts.conf file
The number of <VirtualHost does not match the number of ServerName in d:/wamp/bin/apache/apache2.4.23/conf/extra/httpd-vhosts.conf file

参考:wamp环境下配置vhostspa

相关文章
相关标签/搜索