nrofis
nrofis

Reputation: 9786

PHP server define

I have 2 servers for my PHP project, one for prod and one for tests.

I want to add to the test server a flag to use it in every PHP file. For example to add define('TEST', true)

How can I put this define in the "server level"? I mean that it will be define in the ini or somthing, not in PHP page.

Upvotes: 1

Views: 69

Answers (2)

cmbuckley
cmbuckley

Reputation: 42507

You should use environment variables for this.

In Apache, for instance, you can use mod_env to set an environment variable in your VirtualHost directive for your test server:  

SetEnv APPLICATION_ENV testing

And for your live server:

SetEnv APPLICATION_ENV production

You would then use it in PHP:

$environment = getenv('APPLICATION_ENV');

if ($environment == 'testing') {
    // ...
}

Upvotes: 2

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324750

Personally, I like to use $myname = `hostname`;

Then if the hostname is the name of my test server, put it in test mode.

Alternatives exist, such as checking the HTTP_HOST if you're working on a subdomain. Or you could find out the port being connected on if you use the same domain but another port.

Basically, anything that makes them different, can be used as a check to put you in test mode.

Upvotes: -1

Related Questions