- 1 year ago
Why the directives 'Configuration File (php.ini) Path' & 'Loaded Configuration File' from o/p of phpinfo() are showing entirely different locations?
The "Configuration File (php.ini) Path" and "Loaded Configuration File" values in the output of phpinfo()
may show different locations for various reasons. Let's understand what each of these values means:
Configuration File (php.ini) Path:
This value represents the directory where PHP is searching for thephp.ini
configuration file. It indicates the default location where PHP looks for thephp.ini
file during startup.Loaded Configuration File:
This value shows the actual path to thephp.ini
file that PHP is using for the current execution. It tells you the specific location of thephp.ini
file that PHP successfully loaded during runtime.
The reasons for these values showing different locations could be:
Different
php.ini
Files for CLI and Web SAPIs:
PHP uses differentphp.ini
files for its Command Line Interface (CLI) and Web Server APIs (e.g., Apache, Nginx). It is common to have separatephp.ini
files for CLI and web server SAPIs. Therefore, the "Configuration File (php.ini) Path" will point to the default directory for the CLI version, while the "Loaded Configuration File" will show the path to thephp.ini
file loaded by the web server SAPI.Different PHP Configurations for Different Virtual Hosts:
In web server configurations like Apache or Nginx, you can set different PHP configurations (including differentphp.ini
files) for different virtual hosts or directories. In such cases, the "Loaded Configuration File" will reflect the path of the specificphp.ini
file loaded for that particular virtual host or directory.PHP Configuration Overrides:
PHP allows configuration settings to be overridden at different levels, such as in the mainphp.ini
file, in per-directory.htaccess
files (if using Apache), or in the PHP code usingini_set()
function. These overrides may lead to different values for "Loaded Configuration File" compared to the default "Configuration File (php.ini) Path."Incorrect Configuration Paths:
It is possible that PHP is not correctly set up, or the configuration paths are not specified accurately in the PHP installation. This might cause discrepancies between the two paths.
To determine the actual configuration file being used, you can create a PHP script with the following code:
php<?php
phpinfo();
Run this script on the same SAPI (CLI or web server) that you are using when observing the discrepancy. Look for the "Loaded Configuration File" value in the output to find the actual php.ini
file that PHP is using at runtime. This should help you identify any inconsistencies between the paths shown in the output of phpinfo()
.