?在開(kāi)發(fā)中驼卖,我們本地有多個(gè)項(xiàng)目需要用到apache時(shí),配置虛擬主機(jī)就很方便了莺治。
?在Mac上配置虛擬主機(jī)有三步廓鞠。
- 修改apache配置帚稠,打開(kāi)虛擬主機(jī)。
sudo vim /etc/apache2/httpd.conf
執(zhí)行上述命令床佳, 編輯 httpd.conf 文件滋早,找到
#Include /private/etc/apache2/extra/httpd-vhosts.conf
快捷地查找可以使用
/httpd-vhosts.conf
找到該語(yǔ)句,并把注釋去掉(即去掉'#')砌们。
- 修改虛擬主機(jī)配置文件
sudo vim /etc/apache2/extra/httpd-vhosts.conf
執(zhí)行上述命令杆麸,編輯 httpd-vhosts.conf,修改項(xiàng)目的配置浪感,我給一個(gè)我的自己的例子:
<VirtualHost *:80>
ServerAdmin 17639356@qq.com
DocumentRoot "/Users/ochiashi/Sites/yii-demo"
ServerName admin.demo.com #注意這一行昔头,配置的虛擬域名
<Directory "/Users/ochiashi/Sites/yii-demo">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
這兩個(gè)文件修改完后要重啟apache
sudo apachectl restart
- 配置Mac的hosts文件
sudo vim /etc/hosts
在文件末尾加入:
127.0.0.1 admin.demo.com
這樣就通過(guò)域名訪問(wèn)了。