How to use environments in the Silk Framework

When you're developing an application, it will live in different environements depending on what's happening. For instance, while you're developing, you're connected to a development database with dummy data. When you go to production, you have different database details, debug turned off, etc.

You could put a setup.yml into your config directory and commit it, but that makes for a mess when you deploy your application to production. And if you had a 3rd database for unit testing, that would make or even a bigger mess. Instead, we set it up so we have multiple setup.yml files and copy them into the right place. When you commit to your repository, you add the multiple files, but leave setup.yml out.

mkdir config/development
mkdir config/production

Then add a setup.yml to each of those directories. In that file, put in the specific database connection details, debug settings, etc.

Now, for instance, you check out your code onto your production server. When you check it out, there will be no config/setup.yml file. In order to put it in place, do the following:

php silk.php config env production

This will copy all of the files from config/production to config and you'll be setup and ready to flip on your production site.

Some notes:

  • Environment names aren't limited in what you can call them -- you can use whatever you want, as long as it's a valid directory name.
  • If you're using git for your source code management, you should add 'config/setup.yml' to your .gitignore file so you don't accidentally commit the main setup.yml and mess up the whole thing.

Enjoy

Tags ,