Change php.ini location
Solution 1
PHP uses different .ini
files when running via command line vs running as a web server module. When you grep the results of php -i
your getting the command line ini. It's good practice to have separate ini's for the two environments.
If you must change the directory PHP looks for the php.ini
file, you can use the PHPIniDir
in your web server conf file.
If you wish to just add additional directories to be scanned, you can set the PHP_INI_SCAN_DIR
environment variable.
Solution 2
To Change php.ini file path we have to declare PHPINIDir in the apache configuration file 'httpd.conf' syntax for that is :
PHPINIDir "path_to_ini_file";
Zendy
I'm a frontend web developer. I'm passionate about web standard, responsive web design and performance. I use HTML, CSS, and Javascript everyday, but also learning all those everyday.
Updated on July 27, 2020Comments
-
Zendy almost 4 years
Is it possible to change the location of
php.ini
to be used by Apache? When I didphp -i | grep 'Configuration File'
, the result is:Path => /usr/local/etc
Loaded Configuration File => /usr/local/etc/php.ini
But the result of
phpinfo()
isConfiguration File (php.ini) Path : /etc
I can copy over
php.ini
from/usr/local/etc/
to/etc/
, but is it possible to change the php.ini folder?I installed PHP using homebrew and I am using OS X Snow Leopard.
-
Corbin about 12 yearsIf it's installed as a module, use PHPIniDir.
-
user269867 about 7 years@Zendy how did you solved this?
-
-
Zendy about 12 yearsok, and where do i add that
PHPIniDir
orPHP_INI_SCAN_DIR
? Do i just add it tohttpd.conf
? -
Zendy about 12 yearsOh, and if you don't mind me asking, why is it good practice to have separate ini's for two different environments?
-
webbiedave about 12 years
PHPIniDir
goes inhttpd.conf
.PHP_INI_SCAN_DIR
is an environment variable and needs to be exported via the user that runs apache. Multiple configs is common simply because the environments are different enough to warrant their own settings (one is initiated by the user, the other by anonymous web requests). -
john-jones over 11 yearsMy httpd.conf file is empty and when I add PHPIniDir="path to folder of server" then apache crashes when I restart it. (coming from serverfault.com/questions/469398/…)
-
Abdullah over 10 yearsthanks
export PHP_INI_SCAN_DIR=/etc/php.d/
solved my problem -
David almost 5 yearsThere should be no semicolon at the end, just simply
PHPINIDir "/etc/php.ini"
, and then don't forget to restart your apache (i.e.,sudo apachectl restart
)