How to Find the PHP Ini File

Olorunfemi Akinlua Feb 16, 2024
  1. Use the php --ini CLI Command to Find the PHP ini File
  2. Use get_cfg_var() to Display the PHP ini File Location
How to Find the PHP Ini File

We will discuss in this article the commands or functions to help find the php.ini file within your PC or development environment.

Use the php --ini CLI Command to Find the PHP ini File

Command:

php --ini

If you are on Windows, the returned path could look like this.

C:\php\php.ini

On Windows, go to your Windows Terminal or Windows PowerShell.

search for windows terminal

Once you open your Windows Terminal, type in the command php --ini.

type php –ini

Output:

php –ini command output

Configuration File (php.ini) Path:
Loaded Configuration File:         C:\php\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

You can use the same command via the terminal on Linux.

php –ini on linux

lazycruise@lazycruise:~$ php --ini
Configuration File (php.ini) Path: /etc/php/8.0/cli
Loaded Configuration File:         /etc/php/8.0/cli/php.ini
Scan for additional .ini files in: /etc/php/8.0/cli/conf.d
Additional .ini files parsed:      /etc/php/8.0/cli/conf.d/10-mysqlnd.ini,
/etc/php/8.0/cli/conf.d/10-opcache.ini,
/etc/php/8.0/cli/conf.d/10-pdo.ini,
/etc/php/8.0/cli/conf.d/15-xml.ini,
/etc/php/8.0/cli/conf.d/20-bz2.ini,
/etc/php/8.0/cli/conf.d/20-calendar.ini,
/etc/php/8.0/cli/conf.d/20-ctype.ini,
/etc/php/8.0/cli/conf.d/20-curl.ini,
...

If it is Windows, you can copy the path shown and place it in Windows Explorer to open the php.ini file.

opening phi.ini file

The php.ini will open via the default text editor.

Output:

php ini

On Linux or macOS, you can use the command below.

cat [path of the PHP ini file]

Replace the [path of the PHP ini file] with the path you copied, just like the below syntax.

cat /etc/php/8.0/cli/php.ini

Output:

php ini on linux

Use get_cfg_var() to Display the PHP ini File Location

The command in the previous section works only in the shell. If we need the php.ini file within our PHP code for whatever reason, we can make use of the built-in function, get_cfg_var(), to display or store the absolute path to the php.ini file.

The get_cfg_var() functions gets the value of a PHP configuration option and takes only one parameter/argument, which in this context will be cfg_file_path.

Example:

<?php
$path = get_cfg_var('cfg_file_path');
print_r($path);

Output:

C:\php\php.ini

Depending on the type of PHP installation you have, the path to the php.ini will be different, and the outputs of the code will be different.

For example, if you installed PHP via the XAMPP Application, your php.ini path is most likely this C:\xampp\php\php.ini.

Olorunfemi Akinlua avatar Olorunfemi Akinlua avatar

Olorunfemi is a lover of technology and computers. In addition, I write technology and coding content for developers and hobbyists. When not working, I learn to design, among other things.

LinkedIn