160

I can't find PHP.ini location on my server. I've checked all Stack Overflow answers but I can't find my php.ini location.

I have Linux, Cent OS, zPanel. Last version of PHP.

My computer: Linux Mint 15 KDE.

halfer
  • 19,824
  • 17
  • 99
  • 186
MM PP
  • 4,050
  • 9
  • 35
  • 61

5 Answers5

338

In your terminal/console (only Linux, in windows you need Putty)

ssh user@ip
php -i | grep "Loaded Configuration File"

And it will show you something like this Loaded Configuration File => /etc/php.ini.

ALTERNATIVE METHOD

You can make a php file on your website, which run: <?php phpinfo(); ?>, and you can see the php.ini location on the line with: "Loaded Configuration File".

Update This command gives the path right away

cli_php_ini=php -i | grep /.+/php.ini -oE  #ref. https://stackoverflow.com/a/15763333/248616
    php_ini="${cli_php_ini/cli/apache2}"   #replace cli by apache2 ref. https://stackoverflow.com/a/13210909/248616
Nam G VU
  • 33,193
  • 69
  • 233
  • 372
  • 3
    This is not the php.ini for all things. Its for the CLI. on ubuntu 16.04 / php7.0 (default); this is going to give you /etc/php/7.0/cli/php.ini (or similar) for apache it will be at /etc/php/7.0/apache2/php.ini Php info will only give you the highest level of php.ini; so if you drop info in an html dir, it will show THAT one (not default apache, etc) Please update answer, its near complete ;) – Nick Nov 24 '16 at 17:13
  • 11
    `php -i | grep "php.ini"` is more easy to remember. ;) – ahgood Feb 10 '17 at 03:28
  • 6
    `php -i | grep php.ini` is even easier – Edward Apr 27 '17 at 11:20
  • 1
    note that `php -i` tells the php.ini for CLI **not** the apache's one – Nam G VU Jul 16 '18 at 06:43
  • `php -i | grep /.+/php.ini -oE` gives exact the path [ref](https://stackoverflow.com/a/15763333/248616) – Nam G VU Jul 16 '18 at 06:43
  • 1
    php --ini is doing the same thing right? – Jie Zhang Feb 12 '19 at 20:45
  • 1
    Worked perfect for me. – Mounish Ambaliya Jul 01 '19 at 08:05
  • I got `php: command not found`, I have the Apache module but not the cli. `phpinfo()` works well – lolesque May 26 '23 at 06:46
33

You can find the path to php.ini in the output of phpinfo(). See under "Loaded Configuration File".

enter image description here

Hein Andre Grønnestad
  • 6,885
  • 2
  • 31
  • 43
33

On most installs you can find it here:

/etc/php.ini

TheRealJAG
  • 1,978
  • 20
  • 16
13
php -i |grep 'Configuration File'
srain
  • 8,944
  • 6
  • 30
  • 42
7

#php -i | grep php.ini also will work too!

Rakesh Sankar
  • 9,337
  • 4
  • 41
  • 66
Randeep
  • 533
  • 3
  • 7
  • 18