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

Hi when I echo $_ENV['HOSTNAME'] from a PHP script it no longer works, it used to (I think my server hosting company has changed a setting but I cant think what)

When I run hostname from the command line I get the proper (expected) hostname, also when I do

php -r 'echo $_ENV["HOSTNAME"];'

I get the proper (expected) hostname as well.

Any ideas? Servers are running CentOS.


share|improve this question

The availability of the ENV array indeed depends on the webserver configuration. Inspect the SERVER array or try using gethostname() instead.

share|improve this answer
Hi thanks for the reply. This is code that has worked and hasn't changed, it was happily using $_ENV for a while, I understand that the variables_order can affect this but I dont understand why the SERVER array would now have this value, how/where would this be defined on the server itself? – sam Feb 14 '12 at 14:54
SERVER won't have HOSTNAME, as far as I can tell. I was suggesting that perhaps another variable, like HTTP_HOST, could be used instead. See this question: See this question: Also, this list may come in handy:… – Eduardo Ivanec Feb 14 '12 at 15:06
Hi, that would mean I need to change my code, I'm more interested in finding out what change would have caused this, if its in apache, php etc? – sam Feb 14 '12 at 16:04
I'd say E is probably missing from variables_order in the appropriate php.ini. Is that right? – Eduardo Ivanec Feb 14 '12 at 17:07
nah E is the first one EGPCS we dont have SERVER['HOSTNAME'] set either and nothing in the get, post and cookies :( – sam Feb 14 '12 at 17:13

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.