Imagine you are given a server and you are asked to change its PHP settings. Also, assume that several different versions of PHP are installed on this server. What do you think is the best way to find a PHP configuration file? You will find the answer to this question below.
Method 1 (phpinfo file):
One way to find out exactly which php.ini file your web sever is using is by creating a new PHP file in document root called info.php
<?php phpinfo(); ?>
Load this file in your browser, press CTRL + F and search for “Loaded Configuration File”. You should see something like.
This will tell you the exact location of the php.ini file you want to edit.
Method 2 (PHP.ini & grep command) #
In Linux, run this command to locate the PHP.ini configuration file.
$ php -i | grep "Loaded Configuration File"
Or better way:
$ php -i | grep ini
Or in Windows Command Line:
$ php -i | findstr /c:"Loaded Configuration File"
The result should be something like this.
$ Loaded Configuration File => /etc/php/7.4/cli/php.ini
Method 3 (locate command) #
Using the locate command in Linux. If it’s not already installed, run sudo apt install mlocate [On Debian/Ubuntu] and sudo yum install mlocate [On CentOS/RHEL]
$ locate php.ini
You should see a list of php.ini files here.