A framework for deploying CraftCMS website with Capistrano.
A framework for deploying Craft websites with Capistrano 3.
First thing is to clone this repo to your local machine:
cd my/desired/directory git clone https://github.com/Bluegg/craft-deploy
Craft Deploy contains a bash script that does the initial setup:
Run this (on OS X or Linux) with:
Feel free to remove this file afterwards, as its no longer required.
Windows users, I have no idea how to do this, you're on your own!
From there, you can go ahead and install Craft locally. This framework contains a basic setup for managing different Craft environments, by default it assumes 'local', 'staging' and 'live' environments. To configure your local Craft environment, you will find the config in /craft/config/local/db.php. Here, you enter your 'local' database connection strings.
return array( // The database server name or IP address. Usually this is 'localhost' or '127.0.0.1'. 'server' => 'localhost', // The database username to connect with. 'user' => 'root', // The database password to connect with. 'password' => '', // The name of the database to select. 'database' => '', // The prefix to use when naming tables. This can be no more than 5 characters. 'tablePrefix' => 'craft', );
The local config files are .gitignore'd and so will not be deployed or contained in your repo. Please note, if you remove this from .gitignore, they will be deployed and subsequently cause problems as Craft will look at these for database connection strings.
You will also need to enter the same connection strings in the Capistrano config, found in /cap/deploy.rb:
set :local_db_host, "[db_host]" set :local_db_name, "[db_name]" set :local_db_user, "[db_user]" set :local_db_password, "[db_password]"
Your Craft website must be in a Git repo somewhere that is accessible from your web server (via ssh) and your local machine. We use private repos on Bitbucket, with access provided via ssh. Make sure your Git repo is referenced in /cap/deploy.rb along with ssh credentials.
For Craft Deploy to work, you must have 'passwordless login' ssh access to your webserver. You also need to make sure Git and mysql works on the server, along with any requirements of Craft itself. You will need to create the database on your server, with relevant connection strings entered in both the Craft and Capistrano config files. Adding a task to create remote databases as part of the installation phase is on our roadmap.
Before deploying, we need to run a setup task which will install Craft on your server and create the directories needed:
cap production craft:setup
If everything is set up correctly, you can do your first deployment. To deploy to your production environment:
cap production deploy
Hopefully, everything should go smoothly and Capistrano will do its thing. Problems here are usually related to ssh access to the web server or your Git repo.
Alongside Capistranos various tasks, Craft Deploy adds some useful commands for working with Craft websites.
Craft deploy can push and pull databases (via mysqldump) between environments:
cap production db:push
cap production db:pull
Craft Deploy uses rsync to synchronise assets between enviroments:
cap production craft:sync_assets
For convenience, you can push or pull both databases and sync assets with a single command:
cap production craft:push
cap production craft:pull