How to correctly deploy applications from development to production and how to deal with multiple site configurations.
All my development are done thru SVN located at var/svn/myapp/trunk and
the actual production code is in /var/www/myapp
.
I check out the latest code to my local machine into a directory called "myapp_latest_svn".
I have site and location specific code in my main settings.php
, which has H_PATH = http://myapp.example
& db config settings for db_host, db_user_name and db_password which is as you know different in
local machine settings ( where localhost/myapp.example is just an Apache alias) & on the production ( live site runs on myapp.example
) server.
Also the .htaccess
file is different from that on the production server. In short, there are a number of differences between dev and production.
I keep all my work in SVN. Every morning I use SVN Update which updates the latest code to my local SVN repository. When I am ready to go live, I build a release with SVN Commit.
Then in the release I have to remember to change all the appropriate dev files to their production counterpart.
Now I had to manually edit the production settings.php
& .htaccess
to reflect the site specific changes.
I am looking for an automated way to go from dev to production complete with versioning and no manually editing of files which is error prone and bad practice.
One way is making the production version of files read only (0444). That way when I do a SVN export, they are not overwritten by the dev version of the files and I don't have to worry about editing files on each move from dev to production. But that's bad way of doing things like continuous integration.
Also by making multiple copies of the settings.php
(one for localhost, beta, and prod). Then using a shell script
that exports from SVN, and then once the export is done, it replaces the settings.php
with the correct settings.php
,
depending on the location that we are deploying to. That way everything is automated.
But this is also a lame way to go.
Last way is
if( eregi ("myapp.example$", $_SERVER['HTTP_HOST']) ){
define('H_PATH', 'myapp.example');
} else {
define('H_PATH', 'localmyapp.example');
}
This is fine as far as settings.php
is concerned.
But what abt the .htaccess
, u cannot check like the above in .htaccess
.
What I don't want end up doing every time I deploy my site that I have to change settings.
My DB schema is not in version control so db is not an issue with me, only the settings.php
and .htaccess
.
Also how can I tell SVN not to update some directories since that is also site specific (/log, /cache, /assets, /downloads). Also I need to preserve the Apache ( www_data) write access intact for the above files as well.
Lastly I don't want to copy the empty trunk directory and the .svn files to the production server when I export.
How can I use Phing or even a shell script to integrate without causing any of these issues when building from SVN to production servers?