Location of ini/config files in linux/unix?
- Generally system/global config is stored somewhere under /etc.
- 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:
- Supplied by the user as a command line argument (i.e.
./program -C path/to/config/file.cfg
). - From an environment variable (
char *path_to_config = getenv("PROGRAMCONFIG");
). - 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" andstat
that). - 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:
- 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.
- 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
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
How to Search Contents of Multiple PDF Files
Identify User in a Bash Script Called by Sudo
Search and Replace with Sed When Dots and Underscores Are Present
How to Set Memory Limit for Oom Killer for Chrome
Counter Increment in Bash Loop Not Working
How to Exclude Directories from Grep -R
Bash - How to Pipe Result from the Which Command to Cd
Installing Git with Non-Root User Account
Explaining the 'Find -Mtime' Command
How Is the Linux Kernel Tested
Difference Between Pid and Tid
Linux Bash, Camel Case String to Separate by Dash
How to Have Simple and Double Quotes in a Scripted Ssh Command
Change Path Permanently on Ubuntu
Execute Combine Multiple Linux Commands in One Line
Finding Docker Container Processes? (From Host Point of View)