/ etc / hosts does not affect PHP

I have problems with hosts file and PHP. When you run the PHP code, the entries from / etc / hosts are read as root . 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?

+4
source share
1 answer

Are you sure your /etc/hosts is readable in the world?

chmod a+r /etc/hosts

+9
source

Source: https://habr.com/ru/post/1315903/


All Articles