Skip to content

WordPress Shared Hosting Example

grafikchaos edited this page Apr 5, 2013 · 6 revisions

Deploying AAI-hosted WordPress

These examples are useful if your project will be hosted on an August Ash shared server. In the root directory of your project, run the following commands:

capify .
rm -Rf config/deploy.rb; mkdir -p config/deploy
touch config/deploy/staging.rb config/deploy/production.rb

After you have edited your Capfile and <environment>.rb files, you will need to run the following command only once:

cap <environment> deploy:setup
cap <environment> deploy:check

Capfile

Edit your Capfile to look similar to this (replace any reference to example domains or anything in <CAPS> with valid params):

# Capfile
load 'deploy' if respond_to?(:namespace) # cap2 differentiator

# --------------------------------------------
# :application HAS TO BE DEFINED BEFORE
# REQUIRING 'ash/wordpress_shared_hosting'
# --------------------------------------------
set :application, "<WP_EXAMPLE.com>"

# --------------------------------------------
# Define required Gems/libraries
# --------------------------------------------
require 'ash/wordpress_shared_hosting'

# --------------------------------------------
# Setting defaults
# --------------------------------------------
# IP-address or host's servername
role :app, "<WP_EXAMPLE.com>"
role :web, "<WP_EXAMPLE.com>"
role :db,  "<WP_EXAMPLE.com>", :primary => true

# --------------------------------------------
# Git/SVN Variables
# 
#    Example SVN configuration:
#      set :repository, "https://svn.augustash.com/<PATH/TO/REPO>/trunk"
#      set :scm_username, "<SVN_USER>"
#
#    Example Git configuration:
#      set :repository, "git@github.com:augustash/<REPO_NAME>.git"
#      set :scm, "git"
#      #set :branch, "master" # define which branch 
#                             # should be used for deployments
# --------------------------------------------
set :repository, "git@github.com:augustash/<REPO_NAME>.git"
set :scm, "git"
# uncomment the line below if your project uses submodules (updates submodules)
#set :git_enable_submodules, 1


# SSH login credentials
set :user, "<SSH_USER>"

# Deploy to = file path where the application will reside
set(:deploy_to) { "/home/#{user}/domains/#{application}/code/#{stage}" }

# --------------------------------------------
# Database + File Backup Variables
# --------------------------------------------
# Database credentials
set :dbuser, "<DB_USER>"

# Set Excluded directories/files (relative to the application's root path)
set(:backup_exclude) { [ "wp-content/cache" ] }

# --------------------------------------------
# Compile Sass stylesheets and upload to servers
#
# ONLY RUNS IF YOU HAVE SET :compass_watched_dirs
#
# :compass_watched_dirs can either be a string or an array
#
# Example:
#   # Use the array syntax if you compass watch several directories:
#   set :compass_watched_dirs, ["wp-content/themes/ash", "wp-content/themes/my_custom_theme"]
#   # Use the string syntax if you only compass watch one directory:
#   set :compass_watched_dirs, "wp-content/themes/my_custom_theme"
#
# If you name your public stylesheets directory something
# other than "stylesheets" than you can specify the name of 
# the directory with the :stylesheets_dir_name variable
#
# Examples (both assume your compiled stylesheets exist within your :compass_watched_dirs):
#   # If your Sass compiles to your assets/css directory 
#   # (i.e., `wp-content/themes/my_custom_theme/assets/css`):
#   set :stylesheets_dir_name, "assets/css"
#   # If your Sass compiles to a separate directory 
#   # (i.e., `wp-content/themes/my_custom_theme/styles`):
#   set :stylesheets_dir_name, "styles"
# --------------------------------------------
set :compass_watched_dirs, "wp-content/themes/my_custom_theme"


# --------------------------------------------
# Application Specific Methods
# --------------------------------------------
namespace :app do
  desc "Removes any additional unnecessary files or directories after deploy:finalize_update"
  task :finalize_update, :except => { :no_release => true } do
    logger.debug "Removing additional files"
    run "rm -Rf #{latest_release}/htaccess.dist"
  end
end

# --------------------------------------------
# Callbacks
# --------------------------------------------
before "deploy:update_code", "backup"
after "deploy:finalize_update", "app:finalize_update" 

Production Environment

Edit your config/deploy/production.rb file to look similar to this:

# Deploy WordPress site using Capistrano
#
# Usage:
# cap production deploy:setup
# cap production deploy

# --------------------------------------------
# Variables
# --------------------------------------------
# Database Name
set :dbname, "<DB_NAME>"

# Backups Path (/home/<CLIENT_CODE>/domains/#{application}/code/production/backups)
set :backups_path, "#{deploy_to}/backups"

# --------------------------------------------
# Git/git-flow configuration
#
# if you are using Git or the git-flow workflow
# you should specify the :branch your environment
# deploys from. 
# 
# For example: 
#   + the staging environment should use the `develop` branch
#   + the production environment should use the `master` branch
# --------------------------------------------
set :branch, "master"

Staging Environment

Edit your config/deploy/staging.rb file to look similar to this:

# Deploy WordPress site using Capistrano
#
# Usage:
# cap staging deploy:setup
# cap staging deploy

# --------------------------------------------
# Variables
# --------------------------------------------
# Database Name
set :dbname, "<DB_NAME>"

# Backups Path (/home/<CLIENT_CODE>/domains/#{application}/code/staging/backups)
set :backups_path, "#{deploy_to}/backups"

# --------------------------------------------
# Git/git-flow configuration
#
# if you are using Git or the git-flow workflow
# you should specify the :branch your environment
# deploys from. 
# 
# For example: 
#   + the staging environment should use the `develop` branch
#   + the production environment should use the `master` branch
# --------------------------------------------
set :branch, "develop"