一、配置apache
1、打開httpd-vhosts.conf文件,目錄 /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
在httpd-vhosts.conf 中添加 VirtualHost ,並保存退出
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/zerg/public"
ServerName www.hello.com
</VirtualHost>
DocumentRoot 項目目錄
ServiceName 為虛擬域名
2、打開apache配置文件httpd.conf, 啟用虛擬域名配置,目錄 /Applications/XAMPP/xamppfiles/apache2/conf/httpd.conf
在 httpd.conf 中 添加以下指令:
Include /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
保存退出
二、配置瀏覽器訪問權限(應該是這么說)
打開終端
打開配置文件指令:sudo nano /etc/hosts
輸入密碼:
添加: 127.0.0.1 www.hello.com
保存指令: a、ctrl + x; b、詢問你是否保存,選擇Y; 回車退出;可以再使用sudo nano /etc/hosts 進入文件看看是否保存成功;
三、重啟Apache服務器
四、瀏覽器輸入:www.hello.com,這時候訪問的是public/index.php , 可以正常訪問的情況表示配置成功
六、配置完成之后,我們在瀏覽器中直接訪問 localhost,出錯了,訪問不到了。
解決方法:
在httpd-vhosts.conf 中添加 VirtualHost ,並保存退出
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/"
ServerName localhost
</VirtualHost>
這個是要注意下的
