XAMPP on Mac 配置 Virual Host,xamppvirual
先在hosts檔案裡加入virtual host的網域名稱,指向127.0.0.1 我一般使用的命名規則是dev-domainname.com
sudo nano /private/etc/hosts
# VirtualHosts Mapping127.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 hostsInclude /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,就可以了。