Skip to content

Instantly share code, notes, and snippets.

@djm56
Last active June 24, 2020 11:40
Show Gist options
  • Save djm56/81b2b0ce2ce922412192898db3775c25 to your computer and use it in GitHub Desktop.
Save djm56/81b2b0ce2ce922412192898db3775c25 to your computer and use it in GitHub Desktop.
Setting up wp-config.php using some best practices, setting up environment variables in Apache and using these in wp-config.php. File names for conf files in apache may change depending on your environment.

Intructions for the site conf file in Apache

Find the apache conf file for the website /etc/apache/sites-available/sitename.conf

Edit the file and add the environment variables.

database_name, database_user, database_password and database_host are unique to your MySQL instance.

SetEnv DB_NAME database_name
SetEnv DB_USER dtatabase_user
SetEnv DB_PASSWORD database_password
SetEnv DB_HOST database_host
<?php
//Getting variables from Apache for DB connection information
$db_host = getenv('DB_HOST');
$db_name = getenv('DB_NAME');
$db_user = getenv('DB_USER');
$db_password = getenv('DB_PASSWORD');
// Database Connections
define('DB_NAME', $db_name);
define('DB_USER', $db_user);
define('DB_PASSWORD',$db_password);
define('DB_HOST', $db_host);
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
// You can the keys from here https://api.wordpress.org/secret-key/1.1/salt/
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );
// Please change this prefix.
$table_prefix = 'wp_';
define( 'WP_DEBUG', false );
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS'] = 'on';
define('WP_HOME', 'http://'. $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'http://'. $_SERVER['HTTP_HOST']);
define('WP_CONTENT_URL', '/wp-content');
define('DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST']);
// Define any items above this comment not below
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', dirname( __FILE__ ) . '/' );
}
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment