Mac配置apache虚拟主机

作者: 偏偏注定要落脚丶 | 来源:发表于2018-08-18 23:06 被阅读5次

 在开发中,我们本地有多个项目需要用到apache时,配置虚拟主机就很方便了。
 在Mac上配置虚拟主机有三步。


  1. 修改apache配置,打开虚拟主机。
sudo vim /etc/apache2/httpd.conf

执行上述命令, 编辑 httpd.conf 文件,找到

#Include /private/etc/apache2/extra/httpd-vhosts.conf

快捷地查找可以使用

/httpd-vhosts.conf

找到该语句,并把注释去掉(即去掉'#')。

  1. 修改虚拟主机配置文件
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
  1. 配置Mac的hosts文件
sudo vim /etc/hosts

在文件末尾加入:

127.0.0.1  admin.demo.com

这样就通过域名访问了。

相关文章

网友评论

    本文标题:Mac配置apache虚拟主机

    本文链接:https://www.haomeiwen.com/subject/rrcqiftx.html