-
Notifications
You must be signed in to change notification settings - Fork 12
WordPress Private Server Example
Josh J. edited this page Oct 30, 2013
·
9 revisions
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
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'
# --------------------------------------------
set :application, "<WP_EXAMPLE.com>"
# --------------------------------------------
# Define required Gems/libraries
# --------------------------------------------
require 'ash/wordpress'
# --------------------------------------------
# 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, "[email protected]:augustash/<REPO_NAME>.git"
# set :scm, "git"
# #set :branch, "master" # define which branch
# # should be used for deployments
# --------------------------------------------
set :repository, "[email protected]: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) { "/var/www/#{application}/#{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"
# --------------------------------------------
# NGINX/PHP-FPM configuration
#
# If your web server is using NGINX with PHP-FPM
# you can use the below variables and tasks to
# start/stop/restart/status nginx and php-fpm
# processes. This is especially necessary if you
# are using something like APC to cache your code.
#
# If you are going use these commands it is highly
# suggested that you setup your SSH user to run
# common deploy-related commands (i.e., rm, cp,
# mkdir, chown, chmod, ln, rsync, etc.) as sudo w/o
# requiring a password.
#
# For example, in your `sudoers` file:
# ```bash
# # ....stuff...
#
# # Command Aliases
# Cmnd_Alias DEPLOYMENT = /usr/bin/rsync, /bin/chmod, /bin/chown, /bin/rm, /etc/init.d/nginx, /etc/init.d/php-fpm
# # ...more stuff...
#
# # The COMMANDS section may have other options added to it.
# #
# # Allow root to run any commands anywhere
# root ALL=(ALL) ALL
# <SSH_USER> ALL=NOPASSWD: DEPLOYMENT
# ```
#
# ---------
# Options:
# ---------
# :nginx_init_command (Default: `/etc/init.d/nginx`)
# The path to your nginx control script. You could also use
# `service nginx` but it's experimental at this point.
#
# :phpfpm_init_command (Default: `/etc/init.d/php-fpm`)
# The path to your php-fpm control script. You could also use
# `service php-fpm` but it's experimental at this point.
#
# --------------------------------------------
#after "deploy", "nginx:restart"
# --------------------------------------------
# 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"
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 (/var/www/#{application}/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"
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 (/var/www/#{application}/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"