Find the correct php.ini file

Find the correct php.ini file

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

The Three php.ini Files and Why They Matter

When you run sudo find / -name php.ini, it is tempting to assume that every file returned represents a valid configuration point you can tweak. In reality, finding multiple .ini files on the same system is standard behavior for modern PHP installations, not an error. The confusion usually stems from treating all three variants as if they control the same environment.

The specific paths you identified—/etc/php5/cli/php.ini, /etc/php5/apache2/php.ini, and /etc/php5/cgi/php.ini—correspond to distinct SAPIs (Server Application Programming Interfaces). Each interface has its own memory footprint, execution context, and intended use case. The CLI version is designed for command-line scripts, the CGI handler serves traditional FastCGI setups, and the Apache module handles direct web server integration. Editing one of these files will not affect the others unless you explicitly configure them to do so.

To determine which file actually controls your running instance, you must inspect the active configuration rather than guessing based on file existence. The most reliable method is to execute the following command in your terminal:

php -i | grep "Configuration File"

This output reveals two critical pieces of information. First, Configuration File (php.ini) Path tells you where PHP looks for the default location. Second, and more importantly, Loaded Configuration File points to the exact file currently in use by the CLI interpreter. If your goal is to modify settings for web requests served by Apache, relying solely on this output can be misleading if your CLI environment differs from your web environment.

You mentioned restarting Apache with sudo service apache2 restart, yet changes persisted as if they never happened. This discrepancy often occurs when developers edit the wrong file or fail to account for configuration overrides. In many Linux distributions, such as Ubuntu 14.04 or similar setups using PHP 5.x, the Apache module does not always read from /etc/php5/apache2/php.ini directly. Instead, it frequently loads a virtual host configuration located at /etc/php5/apache2/conf.d/.

If you modified the main php.ini but neglected to check for override directives in the conf.d directory, your changes will be silently ignored. A directive defined in an included file can completely negate a setting in the main config file if it appears later in the inclusion chain. To verify this, inspect the active configuration dump again and look for lines prefixed with ; or those that explicitly mention overrides.

Furthermore, ensure you are editing the correct SAPI. If your web server is running as an Apache module (mod_php), changes to the CLI php.ini will have zero impact on your website. Conversely, if you are using a reverse proxy setup like Nginx with PHP-FPM, the apache2 configuration file is irrelevant; you would need to adjust the cli or fpm variant instead.

Sometimes the solution isn't adding new settings but removing conflicting ones. Check for custom directives in /etc/php5/apache2/conf.d/*.conf that might be resetting your post_max_size. If a value is set to 2M in one file and 20M in another, the latter only applies if it appears after the former in the include order or if the override logic specifically targets the key.

Finally, consider using phpinfo() rather than relying solely on ini_get(). While echo ini_get('post_max_size') is useful for quick checks, a full phpinfo() dump provides a comprehensive view of loaded extensions and their specific configuration paths. This helps identify if an extension-specific config file is overriding global settings.

If you are managing a Laravel application or any framework-sensitive environment, remember that the server's PHP version must match your requirements. Mismatched versions can lead to unexpected behavior where standard directives behave differently due to internal changes in the PHP core between major releases. For production environments requiring high stability and predictable configuration management, ensure your deployment process explicitly defines which php.ini variant is active to avoid these subtle but critical failures.

Our network