• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

config option that's visible to PHP?

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.)


1 Solution
> 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']
pnoericAuthor Commented:
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'].

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

pnoericAuthor Commented:
(this question can be closed, with no answer)
> I ended up using $_ENV['computername'].
what doies this mean? Apache has no environment variable computername
pnoericAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now