/etc/hosts 不影响 PHP

发布于 2024-09-10 04:18:59 字数 359 浏览 8 评论 0原文

我的主机文件和 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁杀 2024-09-17 04:18:59

您是否确保您的 /etc/hosts 文件是世界可读的?

chmod a+r /etc/hosts

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

chmod a+r /etc/hosts

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文