?在開發中,我們本地有多個項目需要用到apache時,配置虛擬主機就很方便了。
?在Mac上配置虛擬主機有三步。
- 修改apache配置,打開虛擬主機。
sudo vim /etc/apache2/httpd.conf
執行上述命令, 編輯 httpd.conf 文件,找到
#Include /private/etc/apache2/extra/httpd-vhosts.conf
快捷地查找可以使用
/httpd-vhosts.conf
找到該語句,并把注釋去掉(即去掉'#')。
- 修改虛擬主機配置文件
sudo vim /etc/apache2/extra/httpd-vhosts.conf
執行上述命令,編輯 httpd-vhosts.conf,修改項目的配置,我給一個我的自己的例子:
<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>
這兩個文件修改完后要重啟apache
sudo apachectl restart
- 配置Mac的hosts文件
sudo vim /etc/hosts
在文件末尾加入:
127.0.0.1 admin.demo.com
這樣就通過域名訪問了。