php.ini is a configuration file which is read when PHP starts up. This file contains various settings that controls the behavior of PHP. The location of the
php.ini file depends on operating system, server configuration, PHP version, and other factors.
This tutorial shows how to find location of the
php.ini configuration file.
In most cases there are different
php.ini files that are used for web server (Apache, Nginx, etc.) and PHP CLI (Command Line Interface).
To determine which
php.ini file is used for web server, create a PHP file in the document root and and add the following code:
phpinfo function prints information about configuration of the PHP. Open a web browser and search for text "Loaded Configuration File" on a page.
On Linux system, the location of the
php.ini file for Apache web server can be something like:
To find out which
php.ini file is used for PHP CLI, run the
php command with
It will call
phpinfo function and print results. To find required line, we can use
grep command on Linux:
php -i | grep "Loaded Configuration File"
findstr command on Windows:
php -i | findstr /c:"Loaded Configuration File"
On Linux system, we will get the output similar to:
Loaded Configuration File => /etc/php/8.0/cli/php.ini