WordPress Capistrano Starter
Table of Contents
Requirements
- Ruby >= 2.0
- Capistrano 3.4.0
- Bundler
- Composer
- Access via SSH Key to Server
Install Ruby
- https://www.ruby-lang.org/de/downloads/
- https://www.ruby-lang.org/de/documentation/installation/
$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x64-mingw32]
Install Capistrano
Capistrano is a remote server automation tool. It supports the scripting and execution of arbitrary tasks, and includes a set of sane-default deployment workflows., (*1)
Howto install: http://capistranorb.com/documentation/getting-started/installation/, (*2)
$ gem install capistrano
$ cap -v
Capistrano Version: 3.4.0 (Rake Version: 10.5.0)
Install Bundler
Bundler is a package manager for Capistrano v3., (*3)
$ gem install bundler
$ bundler -v
Bundler version 1.11.2
Install Composer
Composer is a Dependency Manager for PHP., (*4)
- Howto install https://getcomposer.org/download/
Basic configuration
Go to config/deploy.rb
and configure your application
-name and repo_url
., (*5)
Environment
To configure your environment, go to config/deploy/staging.rb
. The file name equals to your deploy command cap {environment} deploy
e.G. cap staging deploy
)., (*6)
Set your host
, user
and webdir
which is the relative path to your web project on remote server., (*7)
Local development
This Starterkit only represents your wp-content
-directory and does not restrict your local workflow. You can.., (*8)
- Replace your
wp-content
locally.
- Create a symlink to this folder in your WordPress-installation.
- Load WordPress via Composer
- ...
To work with Plugins and Themes, just add them to your composer.json
and run composer install
., (*9)
Remote Server
Directory structure
| /cache
| /deployments
|_ current/ ~> ~/deployments/releases/YYYYMMDDHHIISS/
|__ releases/
|___ <release folders with YYYYMMDDHHIISS>
|__ repo/
|___ <VCS data>
|__ shared/
|___ <linked_files & linked_dirs>
|_ revisions.log
| /tmp
|___ composer.phar
| /www
|___ <WordPress installation>
|___|___ wp-content/ ~> ~/../deployments/current/
| wp-config.php
wp-config.php
To load the correct wp-content/
-folder into your WordPress-installation, you've to add following line to your wp-config.php
:, (*10)
define( 'WP_CONTENT_DIR', realpath( __DIR__ . '/deployments/current' ) );
Commands
View all available commands
$ cap -T
Check if everything is fine
cap {environment} deploy:check
What happens:, (*11)
- Test SSH-connection.
- Check Git-connection.
- Create folders withing
deployments/
.
Deployment and Rollback
$ cap {environment} deploy
What happens:, (*12)
- Read the HEAD of the selected branch.
- Create
shared
-folder if not existing.
- Update
~/deployments/repo
via git checkout
.
- Execute
composer update
.
- Create
release
-folder if not existing.
- Create new folder - with date and time as name - in
release
.
- Copy the current branch from
repo
into this folder.
- Update all symlinks for
releases/{latest release}
and shared/
to current/
.
- Cleanup old releases - by default the last 5 releases.
$ cap {environment} deploy:rollback
What happens:, (*13)
- Change Symlink on
current/
in release/{current release - 1}
.