How to Find PHP.ini Location

Posted on August 26, 2019 at 3:16 pm

Need to know where is located your PHP.ini file?

Locate PHP.ini with Find

The best way (in my opinion) is to use “find” to locate the php.ini:

find / -name php.ini

You should get something like this:

/etc/php/7.3/fpm/php.ini
/etc/php/7.3/cli/php.ini

So this way you will locate PHP.ini for both PHP7 FPM and PHP CLI!

Locate PHP.ini with php –ini

Type this command via your server command-line:

php --ini

You should get something like this (which include the PHP.ini path):

Configuration File (php.ini) Path: /etc/php/7.3/cli
Loaded Configuration File:         /etc/php/7.3/cli/php.ini
Scan for additional .ini files in: /etc/php/7.3/cli/conf.d
Additional .ini files parsed:      /etc/php/7.3/cli/conf.d/10-mysqlnd.ini,
...

Beaware this will get the PHP.ini for PHP CLI!

Use Grep to Locate PHP.ini

Another way is to use grep to extract only the PHP.ini path:

php -i | grep /.+/php.ini -oE

You should get something like this:

/etc/php/7.3/cli/php.ini

Beaware this will get the PHP.ini for PHP CLI!

Use Php_ini_loaded_file() to Locate PHP.ini

Another way is to use php_ini_loaded_file() PHP function:

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

An example output is like this:

Loaded php.ini: /etc/php/7.3/fpm/php.ini

Reference:

https://www.php.net/manual/en/function.php-ini-loaded-file.php

View PHP.ini Location with Phpinfo()

Add phpinfo(); on the first line of a PHP script.

Then visit the PHP script with your browser to view PHP.ini location.

Beaware some hosts may disable phpinfo() function!

Receive updates via email

Other Posts

Updated Posts