A local settings file is one that is never controlled by version control and only contains settings relevant to the server – local, development or live. Often the local settings file is created by an example settings file that has all the relevant settings ready to fill in. The example settings are always committed to version control so that each developer who works on a project can see what they need to fill in when they clone the project.
One other major advantage of not adding the local settings for a project is that it keeps server settings safer because only people with access to the server can see them, unlike a project repo where even if it’s private, any developer with access can see it, and if it’s an open source project then everyone can!
How do I make an example file?
- First take your config or settings file and save it with -example on the end of the file name.
- Go through the file and remove any settings with secret info like database names and passwords with empty values or example values
- Add your example file to your repo.
Example ‘example’ file
Below is a copy of an example file that I created for a small web project:
<?php /* Database settings */ define('USERNAME', 'username'); define('PASSWORD', 'password'); define('DATABASE', 'db_name'); define('HOSTNAME', 'hostname'); /* Table Settings */ define('WORD_TABLE', 'words'); ?>
Using an example file
When you pull it on a new machine you now can simple duplicate it without the -example extension and fill in the database details for your new machine. See a fake example below!
<?php define('USERNAME', 'my_user'); define('PASSWORD', 'hello_there_you123'); define('DATABASE', 'local_database'); define('HOSTNAME', '127.0.0.1'); /* Table Settings */ define('WORD_TABLE', 'the_words'); ?>