Easy way to handle different users / passwords for DB on dev. machine versus production server

Usually I have a configuration file with some global variables for the database connection parameters (for example, host name, db name, user, password).

I also really like being able to simply drag and drop all files from my dev machine to the production server. However, the db development host, etc. May differ from what is on the production server.

Is there an easy way, in PHP, to say something like, "if I'm on a dev machine, use these values ? (I would prefer to avoid hacks based on the host's IP name.) I'm thinking of something like setting something up then in php.ini or httpd.conf, so, for example, $DEV_MACHINE , the dev machine is set to true.

+4
source share
3 answers

You can configure the Apache variable with SetEnv and query it with PHP apache_getenv() .

+2
source

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

If the file is missing, the application displays a warning page about the completion of the installation or simply launches a wizard to configure credentials, etc.

+2
source

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

But the ideal way is to split loans. You do not want prod-Creds to be stolen if the dev server is hacked. So it’s best to suck it and just keep it separate.

+1
source

Source: https://habr.com/ru/post/1332762/


All Articles