Saturday, February 7, 2026
HomeLanguagesHow to know which php.ini file is used ?

How to know which php.ini file is used ?

The php.ini file is the default configuration file used for running applications that require PHP. It is an effective way to work on PHP’s functionality. It is used to control variables like file timeouts, sizes of the upload, and the limits of the resource on which it works.

1. Check php.ini in CGI (Common Gateway Interface): Here, we can use two inbuilt functions to get which php.ini used.

  • php_ini_loaded_file: It retrieves a path to the loaded php.ini file.

    PHP




    <?php
    $php_inipath = php_ini_loaded_file();
      
    if ($php_inipath) {
        echo 'Loaded php.ini is: ' . $php_inipath;
    } else {
        echo 'A php.ini file is not loaded';
    }
    ?>

    
    
  • php_ini_scanned_files: It returns a list of .ini files parsed from the additional ini directory.

    PHP




    <?php
    if ($list_of_files = php_ini_scanned_files()) {
        if (strlen($list_of_files) > 0) {
            $files = explode(', ', $list_of_files);
      
            foreach ($files as $file) {
                echo "<li>" . trim($file) . "</li>\n";
            }
        }
    }
    ?>

    
    

2. Check php.ini in CLI (Command Line Interface): To know about php.ini, simply run on CLI.

php --ini

It look for Loaded Configuration File in output for the location of php.ini used by your CLI.

Note: If we run a PHP script from CLI, it is possible that a different php.ini file will be used than if a server (i.e. apache or Nginx ) runs it.

3. Other Options to know about php.ini:

  • php -i|grep ‘php.ini’
  • Simply create ‘information.php’ file in the web-root and add code(below), and run it in your browser.




    <?php 
    phpinfo(); 
    ?>

    
    
RELATED ARTICLES

Most Popular

Dominic
32491 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6863 POSTS0 COMMENTS
Nicole Veronica
11987 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12076 POSTS0 COMMENTS
Shaida Kate Naidoo
6996 POSTS0 COMMENTS
Ted Musemwa
7238 POSTS0 COMMENTS
Thapelo Manthata
6947 POSTS0 COMMENTS
Umr Jansen
6933 POSTS0 COMMENTS