Can't resolve domain names in php under apache

apache, dns, linux, php

Solution

I had the same problem.

After httpd restart host resolve problem continues. But with httpd stop & start problem solved for me.

Problem

I'm at my wits end with this one. I have apache running on a server of mine (an Amazon ec2 instance), and I can't seem to resolve domain names in php. For example fopen('http://www.google.com', 'r') will throw "php_network_getaddresses: getaddrinfo failed: Name or service not known", but if I change the url to one of google's ip addresses it will work fine. Pinging www.google.com on the remote server works fine as well so I know its not a problem with the "outer system." The peculiar thing is that I've had this server up and running for a while without any issues and I can't think of anything I did that could have caused this. In my php.ini I have allow_url_fopen = On and to make sure it was being applied I ran phpinfo() from the same script that is having this problem and allow_url_fopen is in fact turned on. Any ideas of what else I should try? Could some sort of file permissions problem be causing this? Because I did change some file permissions inside my webapp, and I suppose its possible I mistyped something and accidentally changed permissions/owenership of some files outside of the app. Its highly unlikely but I can't think of anything else I did on the system that could have stopped this from working.

Original source