Tuesday, November 19, 2024
Google search engine
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

Recent Comments