How to Find the Location of php.ini on a Web Server

When running Apache with PHP on a Unix/Linux server, you can find the location of the php.ini file easily. Open a terminal window and type:

php -i | grep php.ini

The server will respond with something like this:

Configuration File (php.ini) Path => /some/path/directory
Loaded Configuration File => /some/path/directory/php.ini

The php.ini file includes the active configuration of the PHP interpreter. To ensure that this file cannot be misused, you should set user privileges on it to 640:

cd /some/path/directory/
sudo chmod 640 php.ini