开发者

Easy way of handling different user / pass for DB on dev. machine vs production server

开发者 https://www.devze.com 2023-01-31 16:30 出处:网络
I usually have a config-file with some global variables for database connectivity settings (such as db host, db name, user, pass).

I usually have a config-file with some global variables for database connectivity settings (such as db host, db name, user, pass).

I also really like to be able to just drag and drop all 开发者_JAVA百科files from my dev machine to the production server. However, development db host etc may be different from the one on the production server.

Is there an easy way of, in PHP, saying something like "if I'm on the dev-machine, use these values"? (I'd prefer to avoid hacks based on host IP / name.) I'm thinking of something like perhaps setting something in php.ini or httpd.conf so that for instance $DEV_MACHINE, is set to true on the dev machine.


You can set up an Apache variable with SetEnv, and query it with PHP's apache_getenv().


I usually use a file called config-local.php which is not under the source control.

If the file is absent, the app shows a warning page saying "finish the setup", or just runs a master to set up database credentials etc.


You can always use the URL. The dev url and the prod url should be different. And should be pretty stable.

But the ideal way is to keep the creds separated. You don't want the prod creds getting stolen if the dev server is hacked. So it is really best to suck it up and just keep them separate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号