準備:下載下傳WampServer3安裝包并安裝成功(建議下載下傳新版本,老版本Bug太多檔案路徑設定雜亂)
1.在apache的conf目錄找到http.conf檔案,去掉下面兩項設定前面的#号
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
#Include conf/extra/httpd-vhosts.conf
2.在Listen 0.0.0.0:80下面再添加一個Listen 0.0.0.0:8088端口(實作多端口配置)
3.在conf\extra檔案夾下找到httpd-vhosts.conf檔案,首先保留伺服器原始路由
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot D:/wamp64/www
<Directory "D:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
3.1 在其下添加下面标簽的虛拟主機設定
(zendStudio12.5是我的workspace檔案夾,wamp64是我的安裝路徑)
<VirtualHost *:8088>
ServerName zendstudio125.com
ServerAlias www.zendstudio125.com
DocumentRoot D:/wamp64/zendStudio12.5
<Directory "D:/wamp64/zendStudio12.5/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName zendstudio125.com
ServerAlias www.zendstudio125.com
DocumentRoot D:/wamp64/zendStudio12.5
<Directory "D:/wamp64/zendStudio12.5/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
4.在系統目錄C:\Windows\System32\drivers\etc下找到hosts檔案并在其中添加上面指定的域名
127.0.0.1 zendstudio125.com (最重要的一步,儲存退出)
PS.這一步指定域名非常重要,看到網上有很多配置介紹都沒有重點強調要修改系統檔案這一步,
有了這步指定,浏覽器才能把域名解析到apache對應的虛拟主機設定
5.重新開機apache服務,在zendstudio12.5檔案夾下建立test.php檔案,測試如下語句
<?php echo 'This dirname is '.dirname(__FILE__);
//結果顯示:This dirname is D:\wamp64\zendStudio12.5 說明虛拟主機設定成功!
Tips:在浏覽器中輸入http://zendstudio125/test.php