首页 > 代码库 > XAMPP on Mac 配置 Virual Host

XAMPP on Mac 配置 Virual Host

先在hosts文件里加入virtual host的域名,指向127.0.0.1 我一般使用的命名规则是dev-domainname.com
sudo nano /private/etc/hosts

# VirtualHosts Mapping
127.0.0.1 dev-domainname.com

接下来配置Apache,打开Apache的配置文件 /Applications/XAMPP/etc/httpd.conf

搜索 “Virtual hosts”
# Virtual hosts
# Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

把第二行注释打开,让Apache去读虚拟主机的配置文件
# Virtual hosts
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

在以上httpd-vhosts.conf里添加Virtual Host的配置
# localhost
<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
    <Directory "/Applications/XAMPP/xamppfiles/htdocs">
        Options Indexes FollowSymLinks Includes execCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

# My custom host
<VirtualHost *:80>
    ServerName mysite.local
    DocumentRoot "/Users/yourusername/path/to/your/site"
    <Directory "/Users/yourusername/path/to/your/site">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog "logs/mysite.local-error_log"
</VirtualHost>

重启Apache,访问dev-domainname.com出现403错误,在httpd.conf里面搜索User Deamon,把deamon改成OS的用户名,重启Apache,就可以了。

XAMPP on Mac 配置 Virual Host