2010-07-16 108 views
4

我遇到了hosts文件和PHP的問題。當運行PHP代碼爲root時,將讀取/ etc/hosts中的條目。但是,不要以我的用戶或Apache的身份運行代碼。/etc/hosts不影響PHP

[email protected]:/# cat /etc/hosts 
127.0.0.1  mydomain.com 

[email protected]:/# php -r "echo gethostbyname('mydomain.com');" 
127.0.0.1 

[email protected]:/$ php -r "echo gethostbyname('mydomain.com');" 
xxx.xxx.xxx.xxx 

任何想法,爲什麼這是?

+1

我不認爲這屬於serverfault,因爲PHP參與:) – Znarkus 2010-07-16 11:20:57

回答

9

你確定你的/etc/hosts文件是世界可讀的嗎?

chmod a+r /etc/hosts

+0

難道不該'A + r'? – Znarkus 2010-07-16 11:57:06

+0

謝謝,那是問題所在!從未有過這樣的問題.. – Znarkus 2010-07-16 12:00:25

+1

在答案中編輯了'a + w',以免Michael混淆別人。 – 2010-07-16 12:16:55