The deployment script is available on GitHub as capistrano-cake.
I use rvm to manage ruby on OS X, but it doesn’t really matter how you do it as long as you can install ruby gems.
The railsless-deploy gem removes most of the railsisms that come with capistrano.
I usually use a shared CakePHP core on my production servers, so deployment from development consists of transferring my app files and dependencies (plugins, etc.). Managing dependencies with Composer is well worth the effort, and allows you to easily add packages from Packagist or from your own private repositories.
My app to deploy is structured like this:
Capfile composer.json Config/ Console/ Controller/ Lib/ Locale/ Model/ Plugin/ Test/ Vendor/ View/ compass/ tmp/ webroot/
I’m splitting up my deploy script into two files,
deploy.rb. This lets me reuse
deploy.rb for every CakePHP deployment, while only changing a few variables in
app.rb. Both of
these files are put in my app’s
Config directory. The
Capfile in the root of my app simply loads
1 2 3 4
Config/app.rb, I set the required variables for deployment:
1 2 3 4 5
The deploy strategy here is that I’m developing the site locally, pushing changes to a private git repository (git.chronon.us), and have the production server (server.chronon.us) pull changes from the git repository.
app.rb configured, I can set things up on the remote server:
This creates two directories on the remove server,
following directories are created by the CakePHP
deploy.rb specifically for a CakePHP app and
permissions are set correctly for the
tmp/ Config/ Plugin/ Vendor/
The config files
database.php are uploaded to
Before deploying, make the necessary changes to these to match your production server environment.
To deploy an app for the first time:
-S composer=install part passes the
install command to the composer task in the deploy script.
By default, composer runs the
update command, so future deployments will require only
Upon deployment, a few special things happen:
Vendordirectories in the app directory on the server are removed, and symlinked to the corresponding directories in the
shareddirectory capistrano made.
Configdirectory are removed, and symlinked to corresponding names in the
The CakePHP tmp directory structure (cache, sessions, tests, logs) is created in
composer.jsonproject file exists, composer runs
install, putting plugins into
shared/Pluginsand vendor files into
If a compass project exists and
set :compile_css, truehas been set in
app.rb, the command
compass compile compassis run locally. The compiled css files are then transferred to the remote server, eliminating the need to compile assets on a production server.
set :compile_js, truehas been set in
app.rb, the command
jammit -c compass/assets.yml -o webroot/js/runs locally. The compiled js files are then transferred to the remote server.
A few other variables can be set in
app.rb, all are optional:
1 2 3 4 5 6
cake_config_files: the config files to symlink and upload during initial setup.
cake_shared_dirs: the directories to symlink from app to shared.
upload_dirs: sets the listed directories to be created in the
shareddirectory and symlinked, just like
compile_css: runs compass compile, requires compass to be set up in your app’s
compile_js: runs jammit, requires an
assets.ymlfile in your app’s
files_to_remove: array of files to delete at the end of deployment.
Obviously this setup is pretty specific to how I have things set up for development. Hopefully all or at least parts of the workflow and script can helpful in deploying CakePHP sites with capistrano.