Question

I have a plain(no framework) php app. I want to deploy my app to PhpFog. The problem is the config(host,dbname) is different.

How to create a db config for development and production environment?

Was it helpful?

Solution

You could use environment variables to do this. PHPFog provides a way to set environment variables in the App Console > Env. Variables tab for your app.

Simply create all the environment variables that you need on both your local machine and on the App Console:

Example:

Local Machine: Edit your .bash_profile

APP_HOST=localhost
APP_DATABASE=mydatabase

PHPfog App Console:

APP_HOST=production.mysqlserver.com
APP_DATABASE=proddatabase

Then access them from your php app:

$db_host = getenv("APP_HOST");
$db_name = getenv("APP_DATABASE");

OTHER TIPS

You can put your config.php in your .gitignore or another solution is to have two branches on your local repository. One to work locally and one to push. Then you define a special merge strategy:

Let's say you want to exclude the file config.php

On branch A:

Create a file named '.gitattributes' in the same dir, with this line: config.php merge=ours. This tells git what strategy to use when mergin the file. In this case it always keep your version, ie. the version on the branch you are merging into.

Add the .gitattributes file and commit

On branch B: repeat steps 1-2

Try merging now. Your file should be left untouched.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top