Search code examples
phpdeploymentcapistranoautomated-deploy

Questions about default deploy Task in Capistrano for PHP project and config.php


I'm having a full day understanding the use of Capistrano. Is really a nice tool that will save me lots of time. I'm actually wanting to use it to deploy one of my many php apps :)

If I have a config.php with an $env="development" variable. Is there any way to make Capistrano change this variable for me to "production" instead? Or I should forget about it and symlink it to shared?

cheers Guillermo


Solution

  • I like to keep such config files separate - it makes it more specific and explicit. How these are kept separate and deployed is at your own discretion. I've had fairly positive results by branching my code for development, staging, and live - but I've also seen situations where a merging in from an external branch (ie three times) is a complete nightmare on bigger projects.

    Alternatively, you might have config.php, config.php.live, etc - but this requires manual maintenance.

    Your miles will obviously vary, my config files tend to have more than one variable differing between deployments, and as such, this extra architecture pays for itself.

    If you do still want to do it with capistrano - you can use sed to change that line using a regular expression:

    sed -i 's/$env=\"development\"/$env=\"production\"/' config.php
    

    obviously, running this once the file is deployed.