PHP bug? PHP can't resolve domains, server can..

Posted by Drifter13, 07-23-2007, 10:51 PM
Hello fellow techs, I'm having a strange problem. My VPS was a clean build 2 weeks ago and so far i have installed cpanel and configured everything and added accounts. I began that one of my scripts that uses gethostbyaddr($ip) was failing to resolve any of the ip's it received. I made another PHP file to test this, with this code: Resulting in: Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Name or service not known The thing is, the VPS is resolving domains just fine I can ping, send emails, even dig: I have no clue what's up, and i think there must be a guru here that has an idea of what is going on?

Posted by Syphic, 07-23-2007, 11:05 PM
Could it be you need to turn the ability in your php.ini file to allow fopen on external URLs? The variable is allow_url_fopen needs to be enabled. See if that could be the problem.

Posted by Drifter13, 07-23-2007, 11:14 PM
Already thought of that, allow_url_fopen On allow_url_include On Here is phpinfo: http://switchwithme.com/phpinfo.php I have curl installed and it is also having the same problem..

Posted by dristi, 07-23-2007, 11:58 PM
Just add target site to /etc/hosts and restart apache, and now You can include a page in that target site from a different site.

Posted by smart_support, 07-24-2007, 01:15 AM
Are you sure rentyourdot.com is resolving from the server ? Did you try something like

Posted by Drifter13, 07-24-2007, 02:15 AM
I am aware of that, but that defeats the purpose of domain resolution as you would need to manually enter such information. @smart_support: You would think it could be that simple, but i have tried multiple domains, not just rentadot.com. The contact form used by my visitors is supposed to resolve their IP to a domain name using this fuction , but it fails for every IP.

Posted by MaximSupport, 07-24-2007, 02:58 AM
Dear Drifter13, Works for me. It might be issue with your DNS Servers. # dig rentyourdot.com Best Regards.

Posted by MaximSupport, 07-24-2007, 03:03 AM
Dear Drifter13, I believe you need to read little bit about function gethostbyaddr(); FYI, http://www.php.net/gethostbyaddr Check out following example and it working fine. Best Regards.

Posted by Drifter13, 07-24-2007, 03:07 PM
I think you misunderstand the problem. My server is able to resolve domains, but PHP on my server is not. For example, functions such as gethostbyaddr() and file_get_contents and curl all do not work. I know exactly what it does, and I'm not sure but i think you just misunderstood the thread. I have taken your exact code and put it on my server to show what is happening: http://switchwithme.com/maxim.php gethostbyaddr fails by echoing the original IP address instead of the resolved domainname. Yet, from my servers root commandline:

Posted by Lightwave, 07-24-2007, 03:36 PM
What version of PHP is this? I'm going to guess 4.something. Have you considered upgrading? Is this PHP installation self compiled, or from a package? --- I dont immagine there's anything wrong with your nsswitch.conf file since normal host resolution works... but could you print the hosts: line of your nsswitch.conf file to be sure Also, what version of glibc do you have installed? Last edited by Lightwave; 07-24-2007 at 03:39 PM.

Posted by Drifter13, 07-24-2007, 04:18 PM
It's version 5.2.3, it was recompiled to the latest version using Cpanel STABLE release. I am not sure if 4.3 had this problem or not, as i immediately upgraded.

Posted by Drifter13, 07-24-2007, 05:04 PM
Oh, i just noticed the other part to your message lol. I thought it was part of your sig. and

Posted by jon-f, 07-24-2007, 05:18 PM
url_fopen and url_include would be the only functions that could restrict that besides your resolvers being wrong. So Id try a recompile if I was you, put a phpinfo up and check all the functions you need

Posted by eger, 07-24-2007, 06:59 PM
Are you running the test php files in a browser? If so, when you are resolving via SSH are you logged in as the same user the web server is running as? I know firewalls like APF can restrict egress based on uid.

Posted by Drifter13, 07-24-2007, 07:33 PM
That is a good idea! I don't have a firewall such as APF installed, but apache is running as nobody. How could i test this?

Posted by eger, 07-24-2007, 08:08 PM
You could just execute the test php file in your first post as the user you are testing normal nslookup or host commands as with the cmdline php. This should tell you if it is a user executing issue. Here's what I get when running the file from command line: If it works under the user where DNS testing was also working then it could be an issue with the user trying to execute or request DNS info. Any selinux, suphp, suhosin, or phpsuexec installed? EDIT: Something else that came to mind is openbasedir protection. Maybe "http://domain.com" is considered outside of your basedir? Last edited by eger; 07-24-2007 at 08:21 PM.

Posted by Drifter13, 07-25-2007, 02:48 PM
Wow, i tried it while logged in as root and the script worked fine! So it would seem you are right. I have no idea how to fix this though. PHPsuexec and such are not installed and httpd runs as nobody. I wanted to also test under the nobody user, but i dont know how to do that either. I guess the obvious solution would be to run apache as root, but i dont know how to do that either.

Posted by eger, 07-25-2007, 02:58 PM
You definitely don't want to run httpd as root... I am not sure where specific users could be denied ports in linux. You might try searching /etc for 'nobody' See if anything shows up in files like /etc/hosts.deny or something that could deny connections. Hopefully someone else will know where specific user tcp or udp connections might be denied.

Posted by Drifter13, 07-27-2007, 03:48 PM
I couldn't find anything that could be filtering connections based on the nobody user. The output seemed pretty generic. I tried changing the httpd.conf for apache to set the user as root, but this caused another problem... Every page that tried to be served gave a 403 Forbidden. I then tried to set the user and group to apache, which auto created an apache user (didnt exist before). This also made the pages being served give a 403. I returned it to nobody and it is working as before. It is so weird... I would not mind running apache as root as long as everything is working, but so far it is FORCING me to run as the nobody user (which seems unable to resolve domains). I have not been able to do a test via ssh as the user 'nobody' because i just get this: [root@server www]# su nobody This account is currently not available. This is so close to being resolved!

Posted by eger, 07-27-2007, 04:41 PM
Check if there is a user and group for 'www'. If not then try your user apache again and at the same time check the permissions for the files being served (and the error_log). If it is a permissions error the error_log should tell you so.

Posted by Drifter13, 07-28-2007, 06:07 PM
Yes, the error_log is giving permission errors. Remember before when i said it was given Forbidden errors when i tried changing the httpd user to something else, even root? I was able to get it running under a new apache user by chowning the files being served with: chown apache:apache /home/switchwi/public_html and then changing the httpd.conf to user apache group apache Surprisingly, nothings changed. I still get the dns resolving errors... so that would kind of eliminate the idea of a firewall blocking the nobody user wouldn't it?

Posted by Steve_Arm, 07-28-2007, 06:14 PM
Have you read this: http://bugs.php.net/bug.php?id=11058

Posted by Drifter13, 07-29-2007, 12:09 AM
Well i totally screwed things up by changing the permissions. I'm having to reload the VPS. Most likely this issue will be fixed after OS reload. Thanks for the help guys, and i recommend if anyone has this issue just DONT BOTHER FIXING IT. -drifter

Posted by Tech Entrance, 09-13-2007, 07:31 PM
So the reload solved this issue ?

Posted by Drifter13, 09-13-2007, 10:42 PM
Yes it did. The problem was some type of permissions problem though, i'm positive of that.

Was this answer helpful?

 Print this Article

Also Read

Question about load balancer

Posted by then00b, 09-05-2007, 06:37 AMHello I'm new to the forums and had a question. Thanks to...

SQL 2005 Express Update

Posted by boonchuan, 05-04-2007, 07:50 AMI am using SQL 2005 Express Management Console in the...

merchant account

Posted by cass, 09-03-2002, 06:33 AMHi, Just hoping someone could advise on why hostcharge seems...

.htaccess question

Posted by MikeWalczak, 10-23-2012, 02:25 PMHey everyone, I've got a question about .htaccess. I...

how to get multiple form values as variables in PHP?

Posted by SoftDux, 03-06-2010, 01:21 PMHi, Can someone please help me with this? I have a...