Where is the php.ini file on a Linux/CentOS PC? [duplicate]
Asked Answered
R

5

162

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.

Rigmarole answered 25/7, 2013 at 6:39 Comment(0)
R
341

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://mcmap.net/q/47710/-where-can-i-find-php-ini
    php_ini="${cli_php_ini/cli/apache2}"   #replace cli by apache2 ref. https://mcmap.net/q/45307/-replace-one-substring-for-another-string-in-shell-script
Rigmarole answered 25/7, 2013 at 6:40 Comment(8)
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 ;)Heart
php -i | grep "php.ini" is more easy to remember. ;)Bischoff
php -i | grep php.ini is even easierBisexual
note that php -i tells the php.ini for CLI not the apache's oneBury
php -i | grep /.+/php.ini -oE gives exact the path refBury
php --ini is doing the same thing right?Species
Worked perfect for me.Ginsburg
I got php: command not found, I have the Apache module but not the cli. phpinfo() works wellHelios
F
35

On most installs you can find it here:

/etc/php.ini
Feed answered 8/4, 2014 at 3:40 Comment(2)
How can you change the loaded configuration file from /usr/local/lib/php.ini to /etc/php.ini ?Intercurrent
@user689017 #19200998Rigmarole
P
33

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

enter image description here

Piet answered 25/7, 2013 at 6:41 Comment(2)
thank you, but i used ITChristian ssh command, thank youRigmarole
No problem, just two different ways of doing it. Might be helpful to others later.Halophyte
T
13
php -i |grep 'Configuration File'
Toxinantitoxin answered 25/7, 2013 at 6:43 Comment(1)
This is my preferred method because you don't have to search the file to see it.Kennithkennon
S
7

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

Siegfried answered 26/7, 2013 at 17:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.