以前寫過一篇關於在Linux環境下配置虛擬主機的文章;
如今又有一種場景;在本地同時寫多個項目;可本地的wamp環境下默認只有一個www目錄;這樣常常修改目錄很痛苦;
那麼幸福就這麼猝不及防的來了;下面就介紹下如何在本地配置wamp多目錄;
示例環境:
wampserver版本:2.5
wamp目錄:E:/tongbu/wamp/php
本地域名:
localhost
test.comhtml
本地目錄:
E:/tongbu/wamp/www/
E:/tongbu/wamp/test/web
想要達到的效果是:
訪問localhost 指向的是E:/tongbu/wamp/www/
訪問test.com指向的是E:/tongbu/wamp/test/apache
1:修改E:/tongbu/wamp/bin/apache/Apache2.2.21/conf/httpd.conf文件
查找看是否有以下代碼
大約在240行bash
<Directory /> AllowOverride none Require all denied </Directory>
若有則替換爲以下代碼;如無則跳過此步驟;ide
<Directory /> Options FollowSymLinks AllowOverride All Order deny,allow Deny from all </Directory>
查找Include conf/extra/httpd-vhosts.conf 刪除註釋#號 大約在474行
搜索 /wamp/www/ 將字體
<Directory "E:/tongbu/wamp/www/"> # # 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 # # 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. # # onlineoffline tag - don't remove Require local </Directory>
替換爲以下內容ui
<Directory "E:/tongbu/wamp/www/"> Options Indexes FollowSymLinks AllowOverride all Order Allow,Deny Allow from all Require local </Directory>
而後在最後添加以下內容this
<Directory "E:/tongbu/wamp/test/"> Options Indexes FollowSymLinks AllowOverride all Order Allow,Deny Allow from all </Directory>
2:修改E:/tongbu/wamp/bin/apache/Apache2.2.21/conf/extra/httpd-vhosts.conf文件spa
<VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "c:/Apache24/docs/dummy-host.example.com" ServerName dummy-host.example.com ServerAlias www.dummy-host.example.com ErrorLog "logs/dummy-host.example.com-error.log" CustomLog "logs/dummy-host.example.com-access.log" common </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "c:/Apache24/docs/dummy-host2.example.com" ServerName dummy-host2.example.com ErrorLog "logs/dummy-host2.example.com-error.log" CustomLog "logs/dummy-host2.example.com-access.log" common </VirtualHost>
將上面這段修改爲以下這段:
<VirtualHost *:80> ServerName localhost ServerAlias localhost DocumentRoot E:/tongbu/wamp/www/ </VirtualHost> <VirtualHost *:80> ServerName test.com ServerAlias www.test.com DocumentRoot E:/tongbu/wamp/test/ </VirtualHost>
3:修改C:Windows/System32/drivers/etc/hosts文件
添加內容以下:
127.0.0.1 localhost 127.0.0.1 test.com
大功告成;在wamp目錄E:/tongbu/wamp/下建立test文件夾;在本地訪問localhost 和 test.com便可
綠色字體部分根據狀況修改成本身本地目錄便可;
最後的最後 必定要記得重啓wamp服務;
如需在Linux環境下Apache配置多個虛擬主機掛載多站點同時運行 可參考:Linux環境下Apache配置多個虛擬主機掛載多站點同時運行
//***************************************華麗的分割線************************************
2016.3.20補充:wampserver已經升級到3.0版本;
新的文章 wampserver配置虛擬主機 有下載連接;
推薦使用3.0版;
本文爲白俊遙原創文章,轉載無需和我聯繫,但請註明來自白俊遙博客https://baijunyao.com 歡迎捐贈讚揚