• The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Issue PHP DNS Lookup Fails

timbarsness

New Pleskian
Plesk Version
# cat /usr/local/psa/version
12.5.30 Ubuntu 14.04 1205160608.09

I've seen this issue now on multiple servers and in two different functions, but the symptoms are the same. The underlying issue seems to be that PHP can't do a DNS lookup. We ran into it with mysql connections and now most recently with file_get_contents().
I created a basic test to simplify the problem:
<?php
$country = "portugal";
$zip = "4600";

$url = "https://maps.googleapis.com/maps/api/geocode/json?address=country ".urlencode($country)."%20".urlencode($zip)."&sensor=false&key=[key removed]";
$result_string = file_get_contents($url);

var_dump($result_string);​

Running this test from the command line works great:
string(1598) "{

"results" : [

{

"address_components" : [

{

"long_name" : "4600",

"short_name" : "4600",

"types" : [ "postal_code", "postal_code_prefix" ]

},

{

"long_name" : "Porto District",

"short_name" : "Porto District",

"types" : [ "administrative_area_level_1", "political" ]

},

{

"long_name" : "Portugal",

"short_name" : "PT",

"types" : [ "country", "political" ]

}

],

"formatted_address" : "4600, Portugal",

"geometry" : {

"bounds" : {

"northeast" : {

"lat" : 41.3752001,

"lng" : -7.892297900000001

},

"southwest" : {

"lat" : 41.1894451,

"lng" : -8.165546899999999

}

},

"location" : {

"lat" : 41.2615809,

"lng" : -8.024700500000002

},

"location_type" : "APPROXIMATE",

"viewport" : {

"northeast" : {

"lat" : 41.3752001,

"lng" : -7.892297900000001

},

"southwest" : {

"lat" : 41.1894451,

"lng" : -8.165546899999999

}

}

},

"place_id" : "ChIJy6K-a9-4JA0RoM87DsHrABw",

"types" : [ "postal_code", "postal_code_prefix" ]

}

],

"status" : "OK"

}

"​
The same from apache fails:
Visit URL: http://[domain-removed]/tim-test.php
Response:
bool(false)
The issue is when trying to do a host lookup, we get a PHP warning and the lookup fails:
AH01071: Got error 'PHP message: PHP Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/vhosts/[path-removed]/tim-test.php on line 32
PHP message: PHP Warning: file_get_contents(https://maps.googleapis.com/maps/ap...y portugal 4600&amp;sensor=false&amp;key=[key removed]): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/vhosts/[path-removed]/tim-test.php on line 32'
So, trying to resolve maps.googleapis.com fails when going through apache but works when run at the command line. Rebooting apache fixes the problem, but it will come back again. Adding a record to /etc/hosts also fixes the problem and makes it not come back, but isn't sustainable.

Question: How do I know how apache is doing a DNS lookup?
 
Hi,

Did you enable SElinux? Could you temporary disable SElinux and check script.

Also, check "getsebool httpd_can_network_connect"
 
SElinux is not enabled:

$ sestatus
The program 'sestatus' is currently not installed. You can install it by typing:
sudo apt-get install policycoreutils
 
Per the article you linked to: do you know how I would test "starting my apache before my network is set up" or change it so apache starts after my network is set up?
 
pls. post the content of your file: => /etc/resolv.conf for further investigations.

# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 168.63.129.16
search kh3mcvbkkotedgeomcrzw5clac.ax.internal.cloudapp.net
 
Hi timbarsness,

pls. inform yourself at: => What is the IP address 168.63.129.16?

If you have further questions to this IP ( and why this or that work, or do not work, when you use it in your network ), pls. consider to contact the Microsoft Azure Support Team, because it is not related to any Plesk product or component. :)
 
HiUFHH01 -- thank you so much for the snarky reply:

If you spent a little more time reading the thread and a little less time trying to make me feel like an idiot, perhaps we might be able to make some progress on this issue. I'll quote some parts of earlier posts, since you can't seem to find the "scroll up" button and read the thread:

I created a basic test to simplify the problem:
Code:
<?php //file: test.php
$country = "portugal";
$zip = "4600";

$url = "https://maps.googleapis.com/maps/api/geocode/json?address=country ".urlencode($country)."%20".urlencode($zip)."&sensor=false&key=[key removed]";
$result_string = file_get_contents($url);

var_dump($result_string);

Those code executes fine with php test.php but when run at http://localhost/test.php it fails with a dns lookup issue. My question is, why does DNS lookup differ between php run with apache and php run from the command line. Since plesk manages both PHP and apache, I see this as a plesk issue. I've also seen this issue both in AWS and Azure, so labeling this as a provider issue is deflecting a serious problem with the platform.
 
Hi timbarsness,

pls. be informed, that my intension to help you with your issues/errors/problems with Plesk products or its components is never meant to make fun of you, nor is it my intention to offend anyone in any form.

I've also seen this issue both in AWS and Azure, so labeling this as a provider issue is deflecting a serious problem with the platform.
No, I consider this to be a misconfiguration at your basic server components, untouched by Plesk, unconfigured by Plesk and not related to Plesk. If I'm wrong with my investigations and suggestions, I deeply ask you to forgive me. :(
 
Back
Top