L
L
LMI2017-06-18 09:58:40
PHP
LMI, 2017-06-18 09:58:40

Mysql data variables in wp-config for Heroku and Apache2 on locale?

There is Wordpress and Heroku. Set up variables for base configs in wp-config as in this article https://adiyatmubarak.wordpress.com/2017/01/20/dep...

See code
// ** MySQL settings - You can get this info from your web host ** //
$url = parse_url(getenv('DATABASE_URL') ? getenv('DATABASE_URL') : getenv('CLEARDB_DATABASE_URL'));
 
/** The name of the database for WordPress */
define('DB_NAME', trim($url['path'], '/'));
 
/** MySQL database username */
define('DB_USER', $url['user']);
 
/** MySQL database password */
define('DB_PASSWORD', $url['pass']);
 
/** MySQL hostname */
define('DB_HOST', $url['host']);
 
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
 
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
 
define('AUTH_KEY',         getenv('AUTH_KEY'));
define('SECURE_AUTH_KEY',  getenv('SECURE_AUTH_KEY'));
define('LOGGED_IN_KEY',    getenv('LOGGED_IN_KEY'));
define('NONCE_KEY',        getenv('NONCE_KEY'));
define('AUTH_SALT',        getenv('AUTH_SALT'));
define('SECURE_AUTH_SALT', getenv('SECURE_AUTH_SALT'));
define('LOGGED_IN_SALT',   getenv('LOGGED_IN_SALT'));
define('NONCE_SALT',       getenv('NONCE_SALT'));

On Heroku I use cleardb for mysql. When I deployed it to production, everything worked.
I'm running WP on an apache2 virtual host on Mac OS. Now there is a database connection error.
And the question is how to make these variables work locally? How to set them in the host config?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2017-06-19
@HeadOnFire

You need .env support. Personally, I actively use Composer in WP development, there is a package " vlucas/phpdotenv " for this purpose ( small lesson ). As far as I know, it is impossible to do this with a regular wp plugin, since .env support must be available at the config level, long before the "plugins_loaded" event.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question