Page 1 of 1

config files for different servers

Posted: Wed Mar 14, 2007 9:45 pm
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

Posted: Wed Mar 14, 2007 9:56 pm
by feyd
Is there a reason they aren't the same?

Thanks

Posted: Wed Mar 14, 2007 10:08 pm
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.

Posted: Wed Mar 14, 2007 10:14 pm
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.

thanks

Posted: Wed Mar 14, 2007 10:25 pm
by johnhelen
If there are not other ways, I will do following this way

Posted: Wed Mar 14, 2007 10:43 pm
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.

Posted: Wed Mar 14, 2007 10:58 pm
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.

Posted: Wed Mar 14, 2007 11:44 pm
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.