tags:

views:

242

answers:

2

Hi guys, I am trying to get into PHP app deployment with Capistrano. I have two config files that I need to be "edited" depending on where I deploy it. It's basic stuff like database name and root url (Codeigniter). Can I make Capistrano edit specified automatically? Let's say I want to edit the following in the file /system/config/edit.php:

$test = '';
// edit to
$test = 'Hello World';

Thanks, Max

+5  A: 

Hi,

What I generally do in this kind of situation (even though I don't use Capistrano) is to have several config files commited to source control.

For instance :

  • config.php for development machines
    • this file is the one that's always used by the application
  • config.testing.php
  • config.staging.php
  • config.production.php

And when deploying the application to the server, I just have to copy the file corresponding to the current environment to "config.php" -- as this one is the one that's always used by the application.

It means that I have to do a file copy during the build process, yes, but :

  • it means there is no need for any search and replace, that can break
  • it also means every config files are commited to SVN (or whatever source control software you are using)


If your configuration files become too complex, and duplicate lots of stuff, you can think about having one "default" config file, that's always included, and sub-config files that only define what depends on the environment.

What that, what I said before still stands : just include the "default" file at the begining of each other.

Pascal MARTIN
A: 

My Unix is knowledge isn't quite up to scratch so I can't quite get the syntax perfect for what you want. However, Capistrano allows you to directly use the Unix command-line by invoking :run_method within your configs.

The Capistrano code might look something like the following:

run "grep -R --files-with-matches '$test = "";' /system/config/ | xargs perl -pi~ -e 's/\$test = "";/$test = "Hello World";/'"

I would check up on that find and replace function working as expected before implementing it live though.

If you need any more help, I'd recommend checking out the Capistrano Handbook, it should answer most of your questions.

KushalP