What is php.ini and where it is located in CentOS

What is php.ini and where it is located in CentOS

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

Stefan Bogdanescu

Founder & Senior Architect

What is php.ini and where it is located in CentOS

When you install a new extension for PHP, the documentation often instructs you to add a line like extension=mongo.so to your configuration file. On systems running Apache or as standalone processes, this file is universally known as php.ini. However, finding it on a Linux distribution like CentOS isn't always as straightforward as looking in /etc/php.ini. The confusion usually stems from the fact that PHP does not have a single, hardcoded location for its configuration; instead, it relies on a specific directive to tell itself where to look.

If you encounter a warning stating "php_ini is not set to php.ini location," your PHP binary has been compiled without knowing which file contains its settings. This often happens when the --with-php-config path is missing during compilation or when the environment variable PHPRC isn't set. Without this explicit knowledge, PHP cannot locate extensions or apply runtime overrides.

How PHP Locates Configuration Files

On CentOS 6 and similar RHEL-based systems, multiple versions of PHP might be installed simultaneously (e.g., the default system PHP and a version installed via EPEL or source). Each version typically maintains its own configuration directory structure under /etc.

For the standard command-line PHP binary, the primary configuration file is indeed named php.ini. However, simply looking for php.ini in /etc might yield results from older packages or unused versions. The most reliable way to identify the active file is to ask the current running PHP binary directly. Running the following command reveals the exact path:

php --ini

This output will list two critical pieces of information:

  1. Loaded Configuration File: The absolute path to the php.ini currently being used by the CLI process.
  2. Configuration File (parsed): Sometimes different from the loaded file if an .conf file is present in a specific directory that overrides parts of the main ini file.

If the output says "No configuration file found," it confirms the warning you saw earlier. In this scenario, PHP is using default compiled-in settings, meaning your new extension won't load because the directive isn't parsed yet.

Correct Placement and Activation

Once you know the correct path—for instance, /etc/php.ini or /etc/php5/cli/php.ini—you can edit the file to include extension=mongo.so. However, there is a significant trade-off regarding how these files are managed on CentOS.

In many default CentOS setups, the system package manager (yum/dnf) manages the PHP configuration. If you manually edit the standard php.ini, your changes might be overwritten the next time you run yum update php or if the package rebuilds. A more robust approach is to create a dedicated file outside the main ini file and reference it, or place your custom extensions in a specific directory that gets automatically included.

For example, on CentOS 6 with PHP-FPM, the structure often looks like this:

  • /etc/php-fpm.d/ contains individual pool configurations.
  • The global settings are still split between php.ini and specific .conf files.

If you must modify the global settings, creating a file named custom.ini in the directory pointed to by the CLI output and adding your extension line there is often safer than editing the monolithic php.ini. Then, ensure that line is uncommented or added at the bottom of the loaded configuration.

Verifying the Installation

After adding the line and restarting your web server (Apache or Nginx with PHP-FPM), you need to verify that PHP actually sees the new extension. You can do this by creating a test script, phpinfo.php, containing:

<?php phpinfo(); ?>

Accessing this via your browser or running it from the CLI will display all loaded modules. If mongo appears in the list under "Loaded Modules," the configuration is correct. If the warning persists, double-check that you are editing the file identified by php --ini, not a stale copy in /etc.

When to Use External Resources

If you are managing a large fleet of servers or deploying complex Laravel applications where PHP configuration becomes a bottleneck, manual file manipulation can become error-prone. In production environments, tools like Ansible or dedicated containerization (Docker) handle these paths automatically to ensure consistency across nodes.

For developers specifically building on top of the Laravel framework, understanding that php.ini is just one layer of configuration is vital. Laravel often uses environment-specific overrides via .env files and composer autoloaders, but it still relies on the underlying PHP extensions being loaded in php.ini. If you encounter issues with specific drivers or caching mechanisms in a Laravel project hosted on CentOS, checking the active php.ini location is often the first step in troubleshooting. For further guidance on configuring PHP specifically for Laravel projects, resources like https://laravelcompany.com offer detailed documentation on optimizing your stack beyond just the ini file.

Our network