/etc/hosts 不影响 PHP
我的主机文件和 PHP 遇到问题。当以 root
身份运行 PHP 代码时,会读取 /etc/hosts 中的条目。但当以我的用户身份或从 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
知道这是为什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否确保您的
/etc/hosts
文件是世界可读的?chmod a+r /etc/hosts
Did you make sure your
/etc/hosts
file is world readable?chmod a+r /etc/hosts