Where can I find php.ini?

后端 未结 14 2320
無奈伤痛
無奈伤痛 2020-11-22 11:58

A few years ago I installed Apache 2.2x and PHP 5.3.1 on a Linux server I maintain. I used .tar.gz\'s and built them as instructed (instead of rpms and what-have-you). And

相关标签:
14条回答
  • 2020-11-22 12:20

    On the command line execute:

    php --ini
    

    You will get something like:

    Configuration File (php.ini) Path: /etc/php5/cli
    Loaded Configuration File:         /etc/php5/cli/php.ini
    Scan for additional .ini files in: /etc/php5/cli/conf.d
    Additional .ini files parsed:      /etc/php5/cli/conf.d/curl.ini,
    /etc/php5/cli/conf.d/pdo.ini,
    /etc/php5/cli/conf.d/pdo_sqlite.ini,
    /etc/php5/cli/conf.d/sqlite.ini,
    /etc/php5/cli/conf.d/sqlite3.ini,
    /etc/php5/cli/conf.d/xdebug.ini,
    /etc/php5/cli/conf.d/xsl.ini
    

    That's from my local dev-machine. However, the second line is the interesting one. If there is nothing mentioned, have a look at the first one. That is the path, where PHP looks for the php.ini.

    You can grep the same information using phpinfo() in a script and call it with a browser. Its mentioned in the first block of the output. php -i does the same for the command line, but its quite uncomfortable.

    0 讨论(0)
  • 2020-11-22 12:21

    For SAPI: php-fpm

    There is no need to create a php.info file (it is not a good policy to leave it for the world to read anyway). On the command line:

    php-fpm -i | more
    

    Somewhere in its output, it will show this line:

    Configuration File (php.ini) Path => /etc
    

    Here is a more complete explanation: https://www.cloudinsidr.com/content/how-to-figure-out-your-php-configuration-parameters-without-info-php/

    0 讨论(0)
  • 2020-11-22 12:23

    Best way to find this is: create a php file and add the following code:

    <?php phpinfo(); ?>
    

    and open it in browser, it will show the file which is actually being read!

    Updates by OP:

    1. The previously accepted answer is likely to be faster and more convenient for you, but it is not always correct. See comments on that answer.
    2. Please also note the more convenient alternative <?php echo php_ini_loaded_file(); ?> mentioned in this answer.
    0 讨论(0)
  • 2020-11-22 12:23

    PHP comes with two native functions to show which config file is loaded :

    • php_ini_loaded_file return the loaded ini file
    • php_ini_scanned_files return a list of .ini files parsed from the additional ini dir

    Depending on your setup, Apache and CLI might use different ini files. Here are the two solutions :

    Apache :

    Just add the following in a php file and open it in your browser

    print php_ini_loaded_file();
    print_r(php_ini_scanned_files());
    

    CLI :

    Copy-paste in your terminal :

    php -r 'print php_ini_loaded_file(); print_r(php_ini_scanned_files());'
    
    0 讨论(0)
  • 2020-11-22 12:28

    In command window type

    php --ini
    

    It will show you the path something like

    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         /usr/local/lib/php.ini
    

    If the above command does not work then use this

    echo phpinfo();
    
    0 讨论(0)
  • 2020-11-22 12:31
    phpinfo();
    

    will tell you its location, or from the command line

    php -i
    
    0 讨论(0)
提交回复
热议问题