Location of Ini/Config Files in Linux/Unix

Location of ini/config files in linux/unix?


  1. Generally system/global config is stored somewhere under /etc.
  2. User-specific config is stored in the user's home directory, often as a hidden file, sometimes as a hidden directory containing non-hidden files (and possibly more subdirectories).

Generally speaking, command line options will override environment variables which will override user defaults which will override system defaults.

Where to save configuration/data files on GNU/Linux?

There's plenty of places that configuration/data files etc could be saved:

  • ~/.config (config, often instead of ~ as it reduces clutter in the user's home directory).
  • ~ (config)
  • /etc
    (config)
  • /var (data)
  • /usr (data)
  • likely many more...

In-depth descriptions of the purposes of the various subfolders of the top-level directories can be found at the links above.


I believe the ad-hoc standard is to use ~/.config for user-specific config files, /var for data files generated during execution, and /etc for "static" system-wide configs. /usr is used for storing user programs and their static data.

More formal standards do exist - the Filesystem Hierarchy Standard expresses the purpose of the top-level directories, while ~/.config is the preferred configuration folder for XDG, and seems to have caught on.

Location of configuration in unix program

It is common to use a series of places to get the location:

  1. Supplied by the user as a command line argument (i.e. ./program -C path/to/config/file.cfg).
  2. From an environment variable (char *path_to_config = getenv("PROGRAMCONFIG");).
  3. Possibly look for a user specific or local version (stat("./program.cfg") or build up a strig to specify either "$HOME/.program/config.cfg" or "$HOME/.program.cfg" and stat that).
  4. Hardcoded as a backup (stat("/etc/program/config.cfg",...)).

Where can I find php.ini?

The best way to find this is:

Create a PHP (.php) file and add the following code:

<?php phpinfo(); ?>

and open it in a browser. It will show the file which is actually being read!

Updates by the OP:

  1. The previously accepted answer is likely to be faster and more convenient for you, but it is not always correct. See comments on that answer.
  2. Please also note the more convenient alternative <?php echo php_ini_loaded_file(); ?> mentioned in this answer.

How do I find the MySQL my.cnf location

There is no internal MySQL command to trace this, it's a little too abstract. The file might be in 5 (or more?) locations, and they would all be valid because they load cascading.

  • /etc/my.cnf
  • /etc/mysql/my.cnf
  • $MYSQL_HOME/my.cnf
  • [datadir]/my.cnf
  • ~/.my.cnf

Those are the default locations MySQL looks at. If it finds more than one, it will load each of them & values override each other (in the listed order, I think). Also, the --defaults-file parameter can override the whole thing, so... basically, it's a huge pain in the butt.

But thanks to it being so confusing, there's a good chance it's just in /etc/my.cnf.

(If you just want to see the values: SHOW VARIABLES, but you'll need the permissions to do so.)

Run mysql --help and you will see:

Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

Sample Image

Where is the php.ini file on a Linux/CentOS PC?

In your terminal/console (only Linux, in windows you need Putty)

ssh user@ip
php -i | grep "Loaded Configuration File"

And it will show you something like this Loaded Configuration File => /etc/php.ini.

ALTERNATIVE METHOD

You can make a php file on your website, which run: <?php phpinfo(); ?>, and you can see the php.ini location on the line with: "Loaded Configuration File".

Update
This command gives the path right away

cli_php_ini=php -i | grep /.+/php.ini -oE  #ref. https://stackoverflow.com/a/15763333/248616
php_ini="${cli_php_ini/cli/apache2}" #replace cli by apache2 ref. https://stackoverflow.com/a/13210909/248616

Config files for libraries on linux?

On Linux the /etc directory is used for configuration files by convention. You might want to consider that. Here is a document for further study http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/etc.html.

Read it, it may help you make the decision



Related Topics



Leave a reply



Submit