default_run_options[:pty] = true set :application, "" set :domain, "" set :user, "" set :group, "" set :runner, "" set :use_sudo, true set :scm, :git set :deploy_via, :remote_cache set :repository, "git@github.com:your-account/your-repo.git" set :deploy_to, "/var/www/#{application}" set :shared_children, %w(.htaccess uploads sitemap cache w3tc) after :deploy, "deploy:cleanup" role :app, domain role :web, domain role :db, domain, :primary => true namespace :deploy do [:start, :stop, :restart].each do |t| desc "Restart nginx" task t, :roles => :app do ['nginx', 'php5-fpm'].each {|svc| sudo "service #{svc} #{t.to_s}" unless t == :finalize_update } end end desc "Setup deploy" task :setup, :roles => :app do run "mkdir -p #{deploy_to} #{deploy_to}/releases #{deploy_to}/shared && chmod g+w #{deploy_to} #{deploy_to}/releases #{deploy_to}/shared" run "mkdir -p #{deploy_to}/shared/uploads #{deploy_to}/shared/sitemap #{deploy_to}/shared/cache" run "touch #{deploy_to}/shared/htaccess.txt #{deploy_to}/shared/advanced-cache.php" sudo "chown -R #{user}:#{group} #{deploy_to}/shared" end desc "Symlink everythang" task :finalize_update, :except => { :no_release => true } do # set permissions on basic folders sudo "chown -R #{user}:#{group} #{latest_release}" sudo "chmod -R g-w #{latest_release}" sudo "chown -R #{user}:#{group} #{shared_path}" sudo "chmod -R g-w #{shared_path}" # cache folder for wp-super-cache sudo "chown -R www-data:www-data #{shared_path}/cache" sudo "chmod -R g+w #{shared_path}/cache" run "ln -nfs #{shared_path}/cache #{release_path}/public/wp-content/cache" # uploads dir sudo "chown -R www-data:www-data #{shared_path}/uploads" sudo "chmod -R g+w #{shared_path}/uploads" run "ln -nfs #{shared_path}/uploads #{release_path}/public/wp-content/uploads" # xml sitemap sudo "chown -R www-data:www-data #{shared_path}/sitemap" sudo "chmod -R g+w #{shared_path}/sitemap" run "ln -nfs #{shared_path}/sitemap/sitemap.xml #{release_path}/public/sitemap.xml" run "ln -nfs #{shared_path}/sitemap/sitemap.xml.gz #{release_path}/public/sitemap.xml.gz" # advanced cache drop-in sudo "chown -R www-data:www-data #{shared_path}/w3tc/advanced-cache.php" sudo "chmod -R g+w #{shared_path}/w3tc/advanced-cache.php" run "ln -nfs #{shared_path}/w3tc/advanced-cache.php #{release_path}/public/wp-content/advanced-cache.php" # the rest of the w3tc files in wp-content sudo "chown -R www-data:www-data #{shared_path}/w3tc/w3tc" sudo "chown -R www-data:www-data #{shared_path}/w3tc/w3-total-cache-config.php" sudo "chown -R www-data:www-data #{shared_path}/w3tc/w3-total-cache-config-preview.php" sudo "chmod -R g+w #{shared_path}/w3tc/w3tc" run "ln -nfs #{shared_path}/w3tc/db.php #{release_path}/public/wp-content/db.php" run "ln -nfs #{shared_path}/w3tc/object-cache.php #{release_path}/public/wp-content/object-cache.php" run "ln -nfs #{shared_path}/w3tc/w3-total-cache-config.php #{release_path}/public/wp-content/w3-total-cache-config.php" run "ln -nfs #{shared_path}/w3tc/w3-total-cache-config-preview.php #{release_path}/public/wp-content/w3-total-cache-config-preview.php" run "ln -nfs #{shared_path}/w3tc/w3tc #{release_path}/public/wp-content/w3tc" # only if using apache # sudo "chown -R www-data:www-data #{shared_path}/htaccess.txt" # run "ln -nfs #{shared_path}/htaccess.txt #{release_path}/public/.htaccess" # only if using super cache # sudo "chown -R www-data:www-data #{shared_path}/wp-cache-config.php" # sudo "chmod -R g+w #{shared_path}/wp-cache-config.php" # run "ln -nfs #{shared_path}/wp-cache-config.php #{release_path}/public/wp-content/wp-cache-config.php" end end require 'erb' require 'open-uri' before "deploy:setup", :db after "deploy:update_code", "db:symlink" set :db_name, '' set :db_user, '' set :db_pass, '' set :db_host, 'localhost' set :db_prfx, 'wp_' set :secret_keys, open('https://api.wordpress.org/secret-key/1.1/salt/').read namespace :db do desc "Create wp-config.php in shared path" task :default do db_config = ERB.new <<-EOF