A configuration file, often shortened to config file, defines the parameters, options, settings and preferences applied to operating systems (OSes), infrastructure devices and applications in an IT context.
Software and hardware devices can be profoundly complex, supporting myriad options and parameters. The operator must explicitly delineate settings and choices that are appropriate for the specifics of the data center, cloud or user environment. Configuration file information specifies, for example, where log files from an application are stored via the storage path, which plug-ins are allowed in a given program, and even the color scheme and dashboard widget preferences in a user interface (UI).
IT systems can work with a single configuration file, or break configurations into multiple files for different components of the system. For example, a complex application can rely on configuration files for UI settings, network parameters, storage parameters and other aspects that must be set up for operation. Multiple configuration files can introduce management difficulties.
The application or other system opens and reads the config file at start time, when it parses and applies each setting. Configuration options may be changed while the application runs, and take effect either immediately or upon restart when the configuration file is re-read.
Configuration file formats and syntax
Configuration files go by many names. Plain text configuration files used in Linux environments have filename extensions such as .cnf, .conf, .cfg, .cf, and .ini. Early command line operating systems such as MS-DOS relied on a single plain-text configuration file with a .sys extension, e.g., config.sys. Common modern configuration filename extensions depend on the prevailing file format, or use .config.
Some configuration files are meant to be human-readable, using plain text compatible with any common text editor. Popular scripting languages such as PHP use a plain-text file, php.ini, and Windows desktops still have a desktop.ini file to configure desktop appearances, icons and other visual characteristics.
Configuration files have largely adopted a serialization format, such as XML, YAML and JSON, to represent complex data structures in a way that is easily stored and parsed. The resulting filenames can reflect the format. For example, a configuration file in YAML format may appear such as myapplication_configuration.yaml. With this setup, administrators identify a modern configuration file by its name rather than by its extension.
Configuration file contents
Configuration file content, while often specific to the corresponding application or system, generally falls into four principal content types: comments, flags, settings, and paths.
Comments are essential to a configuration file, but they do not affect how the file behaves. Comments are the mechanism for developers to communicate intended behaviors and document important actions. For example, the.ini file format has hash and semicolons to mark comments:
# This is a comment in a typical .ini file
Flags control which options are enabled and disabled in an application or system. Flags can be enabled with a numerical one (1) or the word true, and disabled with the numerical zero (0) or the word false. For example, an Ansible configuration file allows a flag related to temporary files with true:
; allow temp files to be world readable
allow_world_readable_tmpfiles = True
In another example, the configuration file specifies whether the name of each task appears in the standard output:
; do not send task labels to the display
display_args_to_stdout = False
Settings are the assignment of constants to variable information, which enables the application to define countless operational parameters. For example, an application might use the variable server to define the IP address of the application server, and the variable port to define the communication port used by the server at the designated IP address:
; set the IP address and port for the application server
server = 126.96.36.199
port = 144
Applications routinely access locations to load or save important information such as log files or plug-ins. While default locations exist, it is common to stipulate storage devices and folder locations via paths, and even specific filenames. The application uses the preferred paths denoted in the configuration file. For example, a path can describe the drive and folder to a configuration file (called dbsettings.ini):
; location of the database config file
database_setup = “c:\\programs\\new\\dbsettings.ini”
Similarly, developers and administrators can use paths to simply delineate desired filenames. For example, a classic config.sys file can stipulate the location and name of the desired UI shell:
; the location and name of the UI shell in MS-DOS 5
shell = c:\dos\command.com
Working with configuration files
People use various tools to create and edit configuration files. Tools can help users find parameters within the file, convert to a different file format, and accomplish other tasks.
Text editors, such as Microsoft Windows Notepad and Linux's GNU nano, are some of the most common tools for editing human-readable files. Some text editors provide search and pattern matching features to help users find and change content.
Other tools specialize in file formats, such as JSON Editor Online to create and edit in the JSON format. Swagger Editor can convert YAML files to JSON. Additional editors exist for formats such as XML, TOML and so on.
To work with configuration files, implement a system of comments, testing, Version control and backups. Use comments to document important activities taking place within the file, and write them in a way that others can understand. Test configuration files thoroughly and ensure that the application or system works as intended. Adopt a naming or version control convention so that configuration file editors can track changes made over time, such as the introduction of a new path for storage, and who made them. Finally, treat configuration files as critical, included in a backup scheme.