A Capistrano based, Composer backed boilerplate project for easy WordPress deployments
Before using this project, I strongly advise reading these articles to get a good overview on how this should work, and what the setup will entail:
- Capistrano v3
- Capistrano/Composer
- Composer on each of your environments (dev/production)
$ git clone https://raw.github.com/netsensei/pressto
$ cd pressto
$ bundle install
$ composer installYou should end up with a folder called pressto with an extra subfolder wp
inside it. This is the actual WordPress installation.
Note that you are installing WordPress from a subfolder on your host. You'll need to follow the Giving WordPress its own directory steps to make sure everything gets loaded correctly.
You'll need a private Git repository which will contain this project:
- Create a repo on i.e. Github or BitBucket or ...
- Either remove the
.gitfolder in this project entirely and do agit initor add your project repo as a remote branch (less recommended) - Important: commit the
composer.lockfile after running composer. - Push the project to your project repo.
Next up, you'll need to configure the Capistrano deployment scripts:
In config/deploy.rb change these lines:
The project name:
set :application, 'projectname'The pointer to your project repo:
set :repo_url, '[email protected]:user/repo.git'SSH connection data of your destination server where you want to deploy to. This assumes you've configured you're sshd and account with a public/private key.
role :app, %w{user@ssh-destination}In config/deploy/{production|staging}.rb change these lines:
The location on the server where the production version will live:
set :deploy_to, '/var/www/example.com'The branch in you project repo which represents the production version:
set :branch, "master"Capistrano keeps static files (ie images, configuration,...) in a separate
shared folder on the remote host.
You'll need to add an uploads/ folder. This contains all your uploaded media.
You'll need to add a config-{development|production|staging}.php file. This
file contains your environment specific db settings.
Example:
<?php
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'PROD_project');
/** MySQL database username */
define('DB_USER', 'PROD_dbuser');
/** MySQL database password */
define('DB_PASSWORD', 'password');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');Capistrano will automatically symlink to these items with each deployment.
If all went well, deployment to i.e. production should not entail much more then this:
$ cap production deploy- Open
composer.jsonand change version number to reflect the upgrade. - Run
composer updateto update locally. This should update your lock file. - Push the updated json and lock file to your repo.
- Run
cap production deployto deploy your changes and upgrade remotely. - Go to your site, login and perform any pending database updates.
Matthias "Netsensei" Vandermaesen http://www.colada.be @netsensei