tags:

views:

60

answers:

1

Hi!

I'm having problems with the hosts file and PHP. When running the PHP code as root, the entries from /etc/hosts are read. But not when running the code as my user, or from apache.

root@server:/# cat /etc/hosts
127.0.0.1       mydomain.com

root@server:/# php -r "echo gethostbyname('mydomain.com');"
127.0.0.1

markus@server:/$ php -r "echo gethostbyname('mydomain.com');"
xxx.xxx.xxx.xxx

Any idea why this is?

+6  A: 

Did you make sure your /etc/hosts file is world readable?

chmod a+r /etc/hosts

Michael Mior
Shouldn't that be `a+r`?
Znarkus
Thank you, that was the problem! Never had such a problem before..
Znarkus
Edited `a+w` in the answer to avoid confusing others if Michael doesn't.
Carl Smotricz
Oops. Thanks Carl!
Michael Mior