2013-03-04 102 views
2

我正在嘗試在本地主機上的我的蘋果mac上設置虛擬主機。服務器由XAMPP提供,它將Apache/MySQL/PHP捆綁在一起。在Mac上在XAMPP上設置虛擬主機

這是我迄今所做的:

編輯/私營/ etc/hosts文件,包括127.0.0.1指向test.myserver.local

127.0.0.1  test.myserver.local 

編輯/應用/ XAMPP /等/額外/的httpd-vhosts.conf到inlcude我的虛擬主機詳情

<VirtualHost *:80> 
    DocumentRoot /Users/???/Documents/workspace/trunk/htdocs 
    ServerName test.myserver.local 
    <Directory "/Users/???/Documents/workspace/trunk/htdocs"> 
    AllowOverride All 
    </Directory> 
</VirtualHost> 

放置一個簡單的index.html在那裏,在它的單詞測試。

我已重新啓動服務器,然後瀏覽到測試網址,以使用Apache的默認頁面而不是我的測試頁面。 虛擬主機文件適用於另一個虛擬主機,代碼被複制時各個位發生變化(即文件夾路徑),主機文件起作用,因爲當Apache關閉時,我的瀏覽器顯示服務器未找到。

爲什麼Apache拒絕顯示我的測試代碼?是否還有其他文件需要更改?我不能想到任何其他人,通常只是那些在Linux/Windows上。

+1

你能告訴我們你在'/ private/etc/hosts','/ Applications/XAMPP/etc/extra/httpd-vhosts.conf'中編輯了什麼,並在問題中更新它嗎?編輯它們後,你重新啓動了Apache服務器嗎? – 2013-03-04 16:47:41

+0

你之後重啓了apache吧? – prodigitalson 2013-03-04 16:48:09

+0

我試過了,但它似乎刪除了我的所有標籤,所以它看起來不錯。我會再嘗試。 – Husman 2013-03-04 16:48:25

回答

0

您是否告訴Apache實際使用基於名稱的虛擬主機?

# Use name-based virtual hosting. 
# 
NameVirtualHost *:80 

我不相信它在Mac上的Xampp中默認啓用。

+0

是的,它已經爲其他一些虛擬主機設置並且可以工作。不管怎麼說,還是要謝謝你。總是有好的第二雙眼睛。 – Husman 2013-03-13 09:39:29

+0

@Danack這個選項到底在哪裏?在'http-vhosts.conf'中? – hitautodestruct 2014-12-08 14:07:26

+0

@hitautodestruct https://www.google.co.uk/search?q=apache+NameVirtualHost – Danack 2014-12-08 15:00:30

5

在XAMPP你需要編輯3個文件來設置虛擬主機

的/ etc/hosts和/Applications/XAMPP/etc/extra/httpd-vhosts.conf像你一樣。

而且還需要編輯/Applications/XAMPP/xamppfiles/etc/httpd.conf到包括HTTP-vhosts.conf

請確保您已註釋掉這一行

# Virtual hosts 
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf 

編輯

你試過就在之前添加此行

Order allow,deny 
Allow from all 
AllowOverride All 
+0

就像我已經說過這個文件已經被引用。我有其他的虛擬主機在那裏工作。 – Husman 2013-03-14 09:34:16

+0

這是我的正確答案! :0) – DataHerder 2013-12-12 18:59:51

+0

什麼是你必須編輯的第三個文件?你剛剛提到2像前面的方法 – 2016-03-24 04:39:07

0

請嘗試將設置爲 「本地主機」,在該文件中包含 「httpd-vhosts.conf」, 即:

# 
# Virtual Hosts 
# 
... 

# others vhost 
<VirtualHost *:80> 
... 
</VirtualHost> 

# localhost 
<VirtualHost *:80> 
    ServerName localhost 
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs" 
    <Directory "/Applications/XAMPP/xamppfiles/htdocs"> 
     Options Indexes FollowSymLinks Includes execCGI 
     AllowOverride All 
     Order Allow,Deny 
     Allow From All 
    </Directory> 
</VirtualHost> 
#end of httpd-vhosts.conf file 

爲我工作,問候結束!