Where can I find php.ini?

Where can I find php.ini?

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

Stefan Bogdanescu

Founder & Senior Architect

Where can I find php.ini?

You've successfully compiled your extension, and you can see ibm_db2.so sitting in $PHP_HOME/lib/extensions/somecomplicatedname/. The installation is physically complete, yet your PHP scripts still fail with a "function not available" error. The missing piece isn't the shared object itself; it's the configuration directive that tells the PHP engine to load it at runtime.

The immediate question is locating php.ini. If you don't know where the active configuration file lives, you are essentially flying blind. You might have a default php.ini in your installation directory, or perhaps none at all if you are running in CLI mode with a custom path. To resolve this ambiguity without guessing, run the php --ini command from your terminal. This single command prints the "Loaded Configuration File" path and lists any additional "Potential Candidate Files."

If the output shows a valid path under Loaded Configuration File, that is where you need to go. Open that file in a text editor and locate the section near the end containing comments about extension=. You will likely see lines commented out like this:

;extension=php_ibm_db2.so

Uncomment it by removing the semicolon and ensure the path is correct relative to your installation. Since you found the file in $PHP_HOME/lib/extensions/somecomplicatedname/, your directive should look something like this:

extension="$PHP_HOME/lib/extensions/somecomplicatedname/ibm_db2.so"

Using the variable $PHP_HOME inside the php.ini file is risky. While some configurations support it, many environments require an absolute path or a relative path calculated at runtime. It is safer to replace $PHP_HOME with the actual directory path you observed during installation.

What happens if php --ini reports that no configuration file was loaded? This is common in shared hosting or when running PHP via the SAPI (Server API) with specific directives. If CLI and Web environments behave differently, you might be looking at a system-wide config but your web server is using a virtual host-specific one located in /etc/php/<version>/apache2/ or /etc/php/<version>/cli/. Check the php --ini output for both; they often point to different files.

Another frequent pitfall involves the extension loading mechanism itself. Modern PHP versions (5.4+) moved away from placing extensions in the main php.ini into a separate directory and using the extension_dir directive. If your ibm_db2.so is inside a subdirectory like somecomplicatedname/, you must set extension_dir to point directly to that parent folder, not the specific extension file:

extension_dir="$PHP_HOME/lib/extensions/somecomplicatedname/"
extension="ibm_db2.so"

Failing to set extension_dir correctly often results in PHP throwing a "failed loading PHP Extension" error rather than just ignoring the function. Without this directive, PHP assumes extensions live immediately next to the php.ini file itself.

If you are unable to find any php.ini files despite checking standard locations like /etc/php/, /usr/lib/php/, or your source root, it is possible that PHP is running without a configuration file entirely, relying solely on hard-coded defaults. In such cases, creating a custom php.ini in the current working directory (for CLI) or placing one in the web server's pool configuration (for Apache/Nginx) is the standard workaround.

For example, you can create a file named cli.ini for command-line usage:

echo "extension=\$PHP_HOME/lib/extensions/somecomplicatedname/ibm_db2.so" > cli.ini
php -d include_path=".:$PHP_HOME/lib/php" -r "require 'cli.ini'; phpinfo();"

However, ensure that the path you provide in include_path does not break existing functionality. Overriding the default include path can cause standard libraries to fail if they expect specific locations. Always test your script with phpinfo() or a simple script checking extension_loaded('ibm_db2') after making changes to verify the extension is actually active.

If you are developing on Linux or macOS, ensure that the dynamic linker can find the shared library dependencies. Sometimes an extension loads in PHP but fails at runtime because the underlying C library (like libdb2) is missing from your system PATH. Check for errors in your PHP error log, which is often located in /var/log/php/ or defined via error_log in your config.

Ultimately, the solution lies in aligning your configuration directives with the physical location of your compiled extension. Once you uncomment the correct line and set the appropriate directory paths, the ibm_db2 functions will become available immediately without needing to reinstall anything.

Our network