Related Articles

Related Articles

How to know which php.ini file is used ?
  • Last Updated : 11 Jun, 2020

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

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?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';
    }
    ?>

    chevron_right

    
    

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

    PHP

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?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";
            }
        }
    }
    ?>

    chevron_right

    
    

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.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?php 
    phpinfo(); 
    ?>

    chevron_right

    
    




My Personal Notes arrow_drop_up
Recommended Articles
Page :