Skip to content

Tutorial: WP Ruby Capistrano

learn2reid edited this page Mar 21, 2014 · 1 revision

Preliminary Notes

SERVER

All sites on server will live in folder “~/sites”

ex) ~/sites/lustfulhealth-dev

Once capistrano = in place, these files will be symlinked.

~ = / {home} / {username}

ex) /home3/lustful1

/home1/thelocia

Cap -T shows all capistrano commands

process = same for prod, staging and dev

SETUP SSH-KEYS ACCESS

1) Subdomain & Database

If creating a site for staging, such as dev.example.com, first you must create the subdomain using cPanel or whatever is provided by hosting service

For BlueHost:

Go to domains and create a new subdomain and have the path be ~/public_html/{subdomain}

ex) dev.lustfulhealth.com == ~/public_html/dev

Create database using cPanel for subdomain

2) Clone WP-Capistrano

Fork / Clone WP-Capistrano Repo

### $ git clone git@github.commailto:git@github.com
learn2reid/wp_capistrano.git ###
### $ git clone git@github.commailto:git@github.com
Kronda/wp_capistrano.git ###

Should now have:

.git, .gitattributes, .git

Cap File

Readme

Config Folder

Deploy folder

dev.rb
staging.rb
prod.rb

deploy.rb

9Wordpress Folder // Where all actual wordpress files are

Webroot Folder5 // Symbolically Linked Folder –all projects live in a folder called webroot

3) Link to Personal GitHub & remove other remotes

On github (or your version of SVN), make a new Repo

should be called your hostname

ex) lustfulhealth, wordcamp, locialnetwork

Grab the ssh code from GitHub

Copy SSH button

Remove other Remotes

Note: to show removes do : git remote -v

git remote rm origin

Add new remote from GitHub

git remote add origin git@github… {COPIED SSH CODE}

git remote add origin ssh://git@bitbucket.org/Learn2reid/d2office.gitssh://git@bitbucket.org/Learn2reid/d2office.git

###

4) Local-config.php

Create “local-config.php” – Get Wordpress Installed Locally

Open Folder in Sublime Text

NOTE: “local-config.php” holds all DB credentials

never put credentials in wp-config for security purposes

Create local-config.php in wordpress folder

touch local-config.php

nano local-config.php

vi local-config.php

Verify that local version works

dev.lustfulhealth.dev

should come up with 2013 wordpress theme

TODO:

ADD WP MULTI CONFIG INSTEAD FOR MULTISTAGING

5) Deploy.rb #FixMe

Set:Application, ‘project_name’ = #{PROJECT_NAME}

NO UNDERSCORES OR DASHES OR SPACES

set: repository

Leave at git

set: app_root, “webroot”

Path to wp within repo

set: local_path, "/home3/lustful1/sites/{app_root}

set: ssh_user, “{name youd use to log in server”

ex) thelocia, lustful1

set: stage, “{leave at dev for most used stage}”

set: local_domain, “dev.locialnetwork.com”

DO NOT ADD HTTP://HTTP:///

OR SLASH AFTER ###

6) Dev.rb #FixMe

Go into main deploy stage – dev.rb

IMPORTANT: ADD set: local_domain, ‘dev.site.dev’ or ‘staging.site.dev’ for each site

Server: All sites live in:

/{home}/{username}/sites/#{application}-#{stage}

ex) /home3/lustful1/sites/lustfulhealth-dev

### ###

WP-CLI settings for any stage.rb file

set :wp, “cd #{current_path}/#{app_root} ; /home3/lustful1/.wp-cli/bin/wp”

# The path to wp-cli

#(Should be the full path to the wp command on your server)

7) Commit & Branch

COMMIT

git add .

git commit -m “Updated Config FIles ”

git push origin master

### ###

BRANCHING: 5Branches should match stages

Development => dev —- Staging => staging

Make new dev branch & switch to it

git checkout -b dev

Push dev branch up to Github

git push -u origin dev

different stages for each stage of development

Git naturally creates master brnace

develop5 in the development5 branch

then merge to staging or prod

Can delete Master brance & jstu pull form stage-specific branches

### ###

role:web, “kronda.com”

role:db, “kronda.com” // usually same as web server

### ###

8) Github & SSH-Keys

Add to SSH-Keys Screen

Follow ssh-keys tutorial

add to config file!!!!!!!!!! SUPER IMPORTANT (esp if you get error: permession denied (publickey)

Host tykaconcepts.com9ForwardAgent yes

9) Deploy:Check

cap dev deploy:check

Dependencies will fail @ first b/c folders ≠ exist yet

10) Deploy:Setup

cap dev deploy:setup

run cap check again after just in case

ignore change group error apache

11) Deploy

If all is good to go, deploy!

$ cap dev deploy

Look for {project_name}-dev

9current // always points to latest release of site

releases 5// History of releases

shared

cached-copy
default
WHERE LOCAL-CONFIG.php exists for SERVER VERSION

12) Server local-config

On LOCAL machine

cap dev deploy:create_settings_php

Puts local-config.php in shared/default folder on server

Open local-config on server and fill in server DB details for that stage.

sftp://lustfulhealth.com//home3/lustful1/sites/lustfulhealth-staging/shared/default/local-config.php

13) Add/Import DB into Server

Manually the first time

Get sql dump from local version

sequel / phpMyAdmin / Navicat / WP Migrate Pro Plugin

DO SEARCH & REPLACE FOR URLS & PATH

Import to Server DB –> phpMyAdmin

14) Push all local content ≠ in repo upto server

To push all local content not in repo up to server

cap dev files:push // in ~/Sites/{project}/wordpress

DOESNT PUSH PLUGINS OR THEMES

15) Symlink - Server Config (Delete original Subdomain & Symlink)

ON SERVER SIDE:

cd ~/sites/current/wordpress && pwd

copy path5 and go back to public_html

ll | grep project_name

ex) ll | grep wordcamp

DELETE Orginal SUBDomain in ~/public_html

rm -rf yourFolderName/

ex) rm -rf wordcamp.karveldigital.com/

Symlink subdomain to sites/project folder

ln -s /{home}/{username}/sites/{project}-{stage}/current/wordpress SPACE /{home}/{username}/public_html/{subdomain}

ex) ln -s /home3/lustful1/sites/lustfulhealth-dev/current/wordpress /home3/lustful1/lustful1/public_html/dev

ll to show that it’s symlinked

## ##

SITE SHOULD BE LIVE AND WORKING AT THIS POINT

DATABASE CONFIG

First Time

a) Create DB folder in Root

### ###

b) #FixMe Search in CapFile

### ###

c) Export DB using WP-CLI

cd ~/Sites/{project}/wordpress

wp db export ../db/default_dev.sql

LOCAL: check in ~/Sites/wordcamp/db to see if it worked, default_dev.sql should exist

wp db export #{filename} –url=#{stage}.lustfulhealth.dev

sed -e ‘s/dev.lustfulhealth.com/staging.lustfulhealth.dev/g’ -i .bak default_dev.sql

d) Push Local DB upto Dev Server

cap dev db:push

e) PULL DB DOWN - db:down & db:pull

2 options: db:down or db:pull

db:down:5 pulls down backup and places it in db folder

cap dev db:down

db:pull:5 pulls down db and replaces local copy with what you pulled /// I EDITED THIS ONE

cap dev db:pull

both do search and replaces

Typical Deploy Process

≠ First Time

1) Deploy

cap {stage} deploy

cap {stage} deploy:check

2) DB: 5wped & wpes – db:push

(in wordpress folder)

wp db export ../db/default_{stage}.sql –url=dev.lustfulhealth.dev’

must include –url=dev.lustfulhealth.dev’ if used local-config.php with case switches

wped = ‘wp db export ../db/default_dev.sql –url=dev.lustfulhealth.dev’

wpes = ‘wp db export ../db/default_staging.sql –url=staging.lustfulhealth.dev’

cap {stage} db:push

3) Files

cap {stage} files:push

TROUBLESHOOTING

Configure WP-CLI on Server

Path to WP-CLI in dev = /{home}/{username}/.wp-cli/bin/wp

must run with PHP-CLI !!!

GTID + mySQL Errors – –set-gtid-purged=OFF

mySQLdump = .wp-cli/vendor/wp-cli/wp-cli/php/commands/db.php

If have GTID error add: –set-gtid-purged=OFF after mysqldump command

Line 123: self::run( Utils\esc_cmd( ‘mysqldump 9–set-gtid-purged=OFF %s’, DB_NAME ), array(

GIT – Commit Line ending errors

find /core/sites/all/modules -type f -exec dos2unix {} +

Cannot Parse Object

Capistrano – Could not parse object ’77514601ab8705e36f26270098b2aa268d9a7899′The easy solution is to go to the server to which you are attempting to deploy and delete the “cached-copy” directory under the “shared” directory.

mysql socket hy002

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

9CSS: HEADER MENUS MESSED UP

Go to wp-admin –> appearance –> 9RESELECT MENUS

### ###

• .htaccess & .htpasswd

91) SERVER:

create .htaccess and .htpasswd files in ~/sites/{project}-{stage}/shared

.htaccess in ~/sites/#{project-name}-dev/shared/.htaccess

# Password Protect AuthType Basic AuthName “Development Area: Locial Network Only” AuthUserFile /home3/lustful1/sites/lustfulhealth-dev/shared/default/.htpasswd require valid-user

.htpasswd ~/sites/#{project-name}-dev/shared/default/.htpasswd

username:<encrypted key from http://davidwalsh.name/web-development-toolshttp://davidwalsh.name/web-development-tools

####

lorelle:F09kytLPCipCE

# Link .htpasswd

run “ln -nfs #{deploy_to}/#{shared_dir}/#{domain}/.htpasswd #{release_path}/#{app_root}/.htpasswd”

run “ln -nfs #{deploy_to}/#{shared_dir}/#{domain}/.htaccess #{release_path}/#{app_root}/.htaccess”

93) GIT COMMIT & REDEPLOY

• Error Documents

See codebox for .htaccess error docs in apache

basically in .htaccess for that stage folder

ErrorDocument code /directory/filename.ext

## ##

Clone this wiki locally