Running the same WordPress code with all credentials on multi-environment (like local, staging & live site) is not an easy job.
The following code will make it easy. Its added multi config file to WordPress and can save different credential with no conflict.
Get started
First download the following code and then add it to the root of your WordPress site.
https://github.com/studio24/wordpress-multi-env-config
Modify the “wp-config.env.php” file and add each environment URL to it.
Finally create a wp-config.”environment”.php file and add the database credential.(Replace environment with local, staging or production)
How it works
The system detects what environment the current website is in and loads the relevant config file for that environment.
By default the environment is defined by the hostname, though you can also set this as an environment variable.
Config files are then loaded according to the current environment. There is support for loading a local config file for sensitive data, which is intended to not be committed to version control.
Example usage:
You need to update the wp-config.env.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | $env = [ 'production' => [ 'domain' => 'domain.com', 'path' => '', 'ssl' => false, ], 'staging' => [ 'domain' => 'staging.domain.com', 'path' => '', 'ssl' => false, ], 'development' => [ 'domain' => 'domain.local', 'path' => '', 'ssl' => false, ], ]; |