wampserver配置多个不同路径站点

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014607184/article/details/81840306

wampserver配置多个不同路径站点

wampserver默认的服务站点为:*:\*\www(wampserver对应的安装地址),但是在开发过程中,我们会把项目部署在不同的路径下,因此就需要为wampserver配置不同路径下的站点。本文采用的wampserver版本为wampserver2.5。不同版本间会存在差距,我也是因为在配置时被网上不同版本的配置方法搞迷糊了,所以记录一下配置过程,以便大家参考以及后续自己需要。


首先确保httpd-vhosts.conf扩展文件引入进来了,部分版本默认是不引入,找到httpd.conf文件,对应路径:D:\wamp\bin\apache\apache2.4.9\conf\httpd.conf,打开后,大概在514行左右,找到对应语句:
这里写图片描述
将前面的注释标志“#”删除,修改如下:
这里写图片描述

接下来就是修改文件httpd-vhosts.conf,增加对应站点路径,httpd-vhosts.conf文件路径:D:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf。我这里增加的站点路径为:F:\myWebsite,为了与默认的localhost区别,这里我用“localtest”,在httpd-vhosts.conf中增加如下语句:

<VirtualHost *:80>
    DocumentRoot "F:/myWebsite"
    ServerName localtest
    <Directory "F:/myWebsite"> 
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Allow from all
        Require all granted
      </Directory> 
</VirtualHost>

这里如果出现了You don t have permission to access / on this server错误,查看一下上述中的这部分是否配置正确:

<Directory "F:/myWebsite"> 
       Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Allow from all
        Require all granted
    </Directory>

接下来还需要修改一下hosts文件,对应路径:C:\Windows\System32\drivers\etc\hosts,增加一行:

127.0.0.1       localtest

如果出现hosts文件无法修改,可以先复制一份到其他路径,修改好之后再替换原来路径的文件。

为了测试,我在F:/myWebsite路径下新建了一个index.php文件:

<?php
    header("content-type:text/html;charset=utf-8");
    echo "<h1>wamp server test</h1>";   
    echo "<br />";
    echo "文件路径:";
    echo __FILE__;
    echo "<br />";
    echo "PHP版本:";
    echo PHP_VERSION;
?>

至此,打开浏览器输入:http://localtest/ 就能看到index.php返回的内容:
这里写图片描述


这时候,如果发现wampserver默认的http://localhost/对应的D:\wamp\www被覆盖了,可以在httpd-vhosts.conf文件增加一下原先localhost对应的路径,类似于重新增加一个站点:

<VirtualHost *:80>
    DocumentRoot "D:\wamp\www"
    ServerName localhost
    <Directory "D:\wamp\www"> 
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Allow from all
        Require all granted
      </Directory> 
</VirtualHost>

如果需要增加其他路径下的站点,可以用以上方法继续添加。

猜你喜欢

转载自blog.csdn.net/u014607184/article/details/81840306
今日推荐