How to find and locate php.ini in linux/unix

When we work in PHP development, we often encounter situations where we modify the php.ini configuration file.

But many people don’t know how to locate php.ini files in the Linux/MAC production and development environment.

How to find and locate php.ini configuration files in Linux/MAC

Using the php -i option, you can display PHP information and configuration information, as well as the location of the php.ini configuration file.

➜  ~ php -i | grep "php.ini"
Configuration File (php.ini) Path => /etc

➜  /etc ll php.ini*
-r--r--r--  1 root  wheel    70K Dec 14 11:23 php.ini.default
-r--r--r--  1 root  wheel    64K Oct  7  2019 php.ini.default-previous

By executing php -i, we can find that php.ini is in the /etc directory. Since it is the default of the system and I have not configured it, there is only one php.ini template file in the etc directory.

Of course, we can also use the php -r command to execute the PHP function “phpinfo()”.

➜  ~ php -r "phpinfo();" | grep "php.ini"
Configuration File (php.ini) Path => /etc

Add a Comment

Your email address will not be published. Required fields are marked *