Search code examples
phpmysqlgitphpfog

Php multiple db environment with git & phpfog


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?


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");