1. 程式人生 > >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,就可以了。