Skip to content

Instantly share code, notes, and snippets.

@scottwakefield
Last active June 6, 2016 08:10
Show Gist options
  • Save scottwakefield/5259b70f92a9ddbc1d1ae864d7c8c662 to your computer and use it in GitHub Desktop.
Save scottwakefield/5259b70f92a9ddbc1d1ae864d7c8c662 to your computer and use it in GitHub Desktop.
#!/bin/bash
# ------------------------------------------------------------------------------
# Create .env file
# ------------------------------------------------------------------------------
cat > .env <<EOL
DB_HOST=localhost
DB_NAME=
DB_USER=
DB_PASS=
EOL
# ------------------------------------------------------------------------------
# Add paths to .gitignore
# ------------------------------------------------------------------------------
touch .gitignore
echo '.env' >> .gitignore
# ------------------------------------------------------------------------------
# Add environment variables to config/db.php
# ------------------------------------------------------------------------------
sed -i "s/.*'server'.*/ 'server' => getenv('DB_HOST'),/" config/db.php
sed -i "s/.*'database'.*/ 'database' => getenv('DB_NAME'),/" config/db.php
sed -i "s/.*'user'.*/ 'user' => getenv('DB_USER'),/" config/db.php
sed -i "s/.*'password'.*/ 'password' => getenv('DB_PASS'),/" config/db.php
<?php
require_once('../vendor/autoload.php');
try {
$dotenv = new Dotenv\Dotenv(dirname(__DIR__));
$dotenv->load();
$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);
} catch (Exception $e) {
exit('Could not find a .env file.');
}
// Path to your craft/ folder
$craftPath = '../';
// Define Paths
define('CRAFT_CONFIG_PATH', '../config/');
define('CRAFT_PLUGINS_PATH', '../plugins/');
define('CRAFT_TEMPLATES_PATH', '../resources/templates/');
define('CRAFT_STORAGE_PATH', '../storage/');
define('CRAFT_TRANSLATIONS_PATH', '../resources/lang/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment