关于PHP项目和config.php的Capistrano默认部署任务的问题

关于PHP项目和config.php的Capistrano默认部署任务的问题

问题描述:

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

我整整一天都在理解使用Capistrano。 真的是一个很好的工具,可以节省我很多时间。 我实际上想用它来部署我的许多php应用程序中的一个:) p>

如果我有一个带有$ env =“development”变量的config.php。 有没有办法让Capistrano改变这个变量给我“生产”呢? 或者我应该忘记它并将它符号链接到共享? p>

欢呼 Guillermo p> div>

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.