Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a number of instances behind a loadbalancer. Is it possible to detect the name of the machine (e.g. in PHP for debugging? I looked through phpinfo() and it doesn't seem to have any kind of machine specific information.

share|improve this question
up vote 3 down vote accepted

you'll have to use $host = system("hostname") or similar as it appears PHP won't provide that info directly.

IP seems a little more involved. Depends on how they've got things set up but you can try

$config = system("ifconfig | grep \"inet addr\"");
preg_match("/(\d{1,3})(\.\d{1,3})/", $config, $matches);
$ip_addr = $matches[1];
share|improve this answer
Hmmm. I think we are getting closer, but all machines are reporting 'p-aws-img-www-02' as the hostname. – Louis W Oct 5 '10 at 14:11
Is there a way to get the machine's (not the domain's) ip address? – Louis W Oct 5 '10 at 14:12

IIRC, the public hostname actually doesn't exist anywhere on the server. It's stored in EC2's metadata, which can be fetched from on any EC2 instance.

$hostname = file_get_contents('');
share|improve this answer

This should do it:

$myservername = $_SERVER['SERVER_NAME'];
share|improve this answer
$_SERVER['SERVER_NAME'] is set to the domain name of my website, not the machine name. Because these are load balanced cloud instances I am sure there is a lot of magic happening behind the scenes. – Louis W Oct 5 '10 at 12:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.