Skip to content

Instantly share code, notes, and snippets.

@craigmdennis
Created September 17, 2014 19:02
Show Gist options
  • Save craigmdennis/6dda452ce8fc3953fbad to your computer and use it in GitHub Desktop.
Save craigmdennis/6dda452ce8fc3953fbad to your computer and use it in GitHub Desktop.
Wordpress multi-environment setup and Capistrano deployment hook
# Namespaced to reduce conflict
namespace :mysite do
desc 'Make a production file'
task :production do
on roles(:app), in: :groups do
execute "touch #{release_path}/env_production"
end
end
end
after 'deploy:updated', 'mysite:production'
<?php
/** Environment variable */
define('WP_ENV', 'staging');
/** The name of the database for WordPress */
define('DB_NAME', '');
/** MySQL database username */
define('DB_USER', '');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname (Media Temple) */
define('DB_HOST', $_ENV['DATABASE_SERVER']);
/** Server name (your url) */
$domain_name = 'http://dev.mysite.com';
/* For developers: WordPress debugging mode. */
define('WP_DEBUG', false);
?>
<?php
/** Absolute path to files directory containing the wordpress folder */
$domain_dir = dirname(__FILE__);
// ** Check to see if a local config file exists ** //
if ( file_exists( $domain_dir . '/local-config.php') ) {
/** If it does exist, then use it */
include( $domain_dir . '/local-config.php');
/** Environment variable */
define('WP_ENV', 'local');
/* For developers: WordPress debugging mode. */
define('WP_DEBUG', true);
}
else if ( file_exists( $domain_dir . '/env_staging') ) {
/** Environment variable */
define('WP_ENV', 'staging');
/** The name of the database for WordPress */
define('DB_NAME', '');
/** MySQL database username */
define('DB_USER', '');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname (Media Temple) */
define('DB_HOST', $_ENV['DATABASE_SERVER']);
/** Server name (your url) */
$domain_name = 'http://dev.mysite.com';
/* For developers: WordPress debugging mode. */
define('WP_DEBUG', false);
}
else {
// ** MySQL settings - You can get this info from your web host ** //
/** Environment variable */
define('WP_ENV', 'production');
/** The name of the database for WordPress */
define('DB_NAME', '');
/** MySQL database username */
define('DB_USER', '');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Server name (your url) */
$domain_name = 'http://mysite.com';
/* For developers: WordPress debugging mode. */
define('WP_DEBUG', false);
}
define('WP_SITEURL', $domain_name . '/wp');
define('WP_HOME', $domain_name);
define('WP_CONTENT_URL', $domain_name . '/content');
define('WP_CONTENT_DIR', $domain_dir . '/content');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment