config files for different servers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

config files for different servers

Post by johnhelen »

Hello all

I have config files containing $host, $dbname, $username and $passwords for different servers: local computer, stagging and production as the following:


config-local.php
$host='localhost';
$dbname='database_local';
.....

config-staging.php
$host='staging_host';
...

config-server.php
....
...

In database.inc.php, I need to include this file for database access. In my local computer, I can have

include('config-local.php');
.....

However, if I want to put this application into the staging server, I have to change this as the following:

include('config-staging.php');
.....

There is better way????- I am using apache server. I can change those values for variables directly at staging or server but I think that is not good way

Any idea

Thanks for any help
sho
Last edited by johnhelen on Wed Mar 14, 2007 10:01 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Is there a reason they aren't the same?
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

Thanks

Post by johnhelen »

I it can be the same.

However, in my local computer, I have a database name, username, pass for this application with data, But when I put this application into server, I need to have other names/pass.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I just always call it config.php and edit it for each system. I tend to keep config.php outside the application directory (which is separate from the public HTML directory) to make updates easier.
(#10850)
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

thanks

Post by johnhelen »

If there are not other ways, I will do following this way
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What sort of ways are you looking for?

It may be possible to detect which one to use programmatically by analyzing the $_SERVER and/or $_ENV variables.
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

Post by johnhelen »

The way I am looking for is the way that I only need to upload those files into staging and server. Staging and server can findout the suitable config.php automatically. So I donot have to change value in staging and server.
visitor-Q
Forum Commoner
Posts: 72
Joined: Mon Feb 05, 2007 1:40 am

Post by visitor-Q »

arborint wrote:I just always call it config.php and edit it for each system. I tend to keep config.php outside the application directory (which is separate from the public HTML directory) to make updates easier.
it's also more secure that way.
Post Reply