We help IT Professionals succeed at work.

config option that's visible to PHP?

pnoeric asked
Medium Priority
Last Modified: 2010-05-18
I have a staging server and a live server, and I run the same code base on both... there's some directives in the PHP to change paths, etc, if it's running on staging. But for that to work, the PHP Script has to be able to ID the machine it's on. (I prefer this to setting a flag every time I want to move the code from staging to live.)

I tried using  "if(stristr($_SERVER['HTTP_HOST'], 'localhost'))" which works (since my local apache that I use for testing is just http://localhost)... except I run it on a couple of different staging servers that both resolve as localhost.

Is there some minor Apache option I could set, that would be retrievable in PHP?

(I say minor, since I could probably change 'localhost' to something more machine-specific, but I'd prefer not to. Ideally, it'd be some kind of minor PHP flag I could set in the httpd.conf file, then PHP could just check that.)


Watch Question

Top Expert 2008

> it'd be some kind of minor PHP flag I could set in the httpd.conf file, then PHP could just check that.

You might set an apache ENV

SetEnv local 1

should make the ENV 'local' available containing the value 1
how about using $_SERVER['SERVER_NAME'] or $_SERVER['SERVER_ADDR']


unfortunately, the 'SetEnv' didn't work-- I added it but it never showed up in phpinfo() or $_ENV or $_SERVER.

I ended up using $_ENV['computername'].



(this question can be closed, with no answer)
> I ended up using $_ENV['computername'].
what doies this mean? Apache has no environment variable computername


hmm, it showed up in my apache config-- you know, it might be because I'm using this on my local environment, which is a windows pc. it's fine if my staging and dev servers (both linux) don't have computername, since the test will just fall through.
PAQed with points refunded (125)

Community Support Moderator

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.