Usage as Composer post-package-install script. Auto generation of wp-config.php
files for
WordPress installs. This package mostly is a convenience package that should make the build process
easier.
This package is a wp-config.php
generator for WordPress that runs as Composer Script.
It is based up on Vance Lucas PHPDotEnv package that
offers a solution for adding a not version controlled/ignored .env
file. The key/value data
is made available as getenv()
, $_ENV
and $_SERVER
variable afterwards. This config
generator fetches a maintained list of configurable WordPress constants (like DB credentials)
and builds a wp-config.php
file in the WordPress root directory. This does not make increase
security, but it helps preventing that you push sensitive information to a version controlled
repository. It also makes it easier to maintain different environments like development,
staging and production.
Example:
We recommend to use something like Andreys/"@Rarst" recipe for a site stack to get a thoughtful base structure for your project. Simply add this package to your stack.
"config" : {
"vendor-dir": "wp-content/vendor"
},
// ...
"require" : {
// ... other software installed to /var/www/wp-content/vendor
"wecodemore/wp-composer-config" : "1.x-dev"
},
Then setup the script
"scripts" : {
"post-package-install" : [
"WCM\\WPComposerConfig\\WPConfigCommand::postPackageInstall"
]
},
Finally the script needs some variable set for the extra
object:
"extra" : {
"wordpress-install-dir" : "path/to/wordpress",
"wordpress-env-dir" : "path/to/the/.env/file
}
That's it.
If you want to run it on demand, you might want to give it a custom name that you can
refer to on the command line. Avoid config
as this is an internal Composer command:
"scripts" : {
"wp-config" : [
"WCM\\WPComposerConfig\\WPConfigCommand::postPackageInstall"
]
},
This way you can simply enter
composer wp-config
in your CLI and run it whenever it pleases you.
The check list:
- Make sure that you add
.env
to your.gitignore
file - Take a look at the
/ci
folder in this package and copy the.env.example
contents to your projects.env
file. This is a blueprint of all major versions - Adjust the settings that you find there
- Add the setup steps described above to your
composer.json
file - Open your CLI and enter
composer install
- Auth keys and Salt get fetched directly from the wordpess.org servers
The following options are mirrored by the package over from PHPDotEnv:
Comment: Prefix a line with #
.
Empty string: Set a =
after your key without a value
The following option is new and only works for auto generating the wp-config.php
file.
This should make it easier to test different settings without adding and deleting the same
constants over and over again.
Use WP Default: Set neither a =
, nor a value for that key. Or just don't set it at all.
The package does not overwrite already existing Auth Keys and Salts. If you need them to be regenerated, please just delete them from the config by hand. They will get added again with a new set of hashes directly from wp.org.
A: Switching from the (default) single site install to a multi site install is a multi step
process that involves user interaction, changing the .htaccess
file
and adding constants step by step. We don't want to mess up your repo, so we don't do that by
now. But if you think you can make it happen, just fork the repo and send a Pull Request.
A: The package is on Packagist and auto updated from GitHub instantly (using WebHooks).
A: Just ask in a new issue. We discuss everything with everyone. If you got a PR, even better.
A: We use semantic versioning, so you will want to stay up to date with major versions.