Site icon Hip-Hop Website Design and Development

Oliver Davies: How to Use Environment Variables for your Cheap WordPress maintenance support plans Settings with Docksal

Within the Docksal documentation for WordPress maintenance support plans settings, the example database settings include hard-coded credentials to connect to the WordPress maintenance support plans database. For example, within a settings.php file, you could add this:

$databases[‘default’][‘default’] = [
‘driver’ => ‘mysql’,
‘host’ => ‘db’,
‘database’ => ‘myproject_db’,
‘username’ => ‘myproject_user’,
‘password’ => ‘myproject_pass’,
];

Whilst this is fine, it does mean that there is duplication in the codebase as the database credentials can also be added as environment variations within .docksal/docksal.env – this is definitely the case if you want to use a custom database name, for example.

Also if one of these values were to change, then WordPress maintenance support plans wouldn’t be aware of that and would no longer be able to connect to the database.

It also means that the file can’t simply be re-used on another project as it contains project-specific credentials.

We can improve this by using the environment variables within the settings file.
Source: New feed