PHP和PHP-FPM都可以用参数-c指定php.ini配置文件.
执行下列命令可见:
strace -f -o strace.log \
/png/php/5.4.45/bin/php -v && \
cat strace.log|egrep 'open|read'|grep 'ini'
3080 open("/png/php/5.4.45/bin/php-cli.ini", O_RDONLY) = -1 ENOENT (No such file or directory)
3080 open("/png/php/5.4.45/lib/php-cli.ini", O_RDONLY) = -1 ENOENT (No such file or directory)
3080 open("/png/php/5.4.45/bin/php.ini", O_RDONLY) = -1 ENOENT (No such file or directory)
3080 open("/png/php/5.4.45/lib/php.ini", O_RDONLY) = 3
PHP会优先读取php程序所在目录下的php-cli.ini,访问到则不再读取其他ini文件.
PHP-FPM情况如下:
strace -f -o strace.log \
/png/php/5.4.45/sbin/php-fpm -v && \
cat strace.log|egrep 'open|read'|grep 'ini'
3537 open("/png/php/5.4.45/lib/php-fpm-fcgi.ini", O_RDONLY) = -1 ENOENT (No such file or directory)
3537 open("/png/php/5.4.45/lib/php.ini", O_RDONLY) = 3
PHP-CGI情况如下:
strace -f -o strace.log \
/png/php/5.4.45/bin/php-cgi -v && \
cat strace.log|egrep 'open|read'|grep 'ini'
3568 open("./php-cgi-fcgi.ini", O_RDONLY) = -1 ENOENT (No such file or directory)
3568 open("/png/php/5.4.45/bin/php-cgi-fcgi.ini", O_RDONLY) = -1 ENOENT (No such file or directory)
3568 open("/png/php/5.4.45/lib/php-cgi-fcgi.ini", O_RDONLY) = -1 ENOENT (No such file or directory)
3568 open("./php.ini", O_RDONLY) = -1 ENOENT (No such file or directory)
3568 open("/png/php/5.4.45/bin/php.ini", O_RDONLY) = -1 ENOENT (No such file or directory)
3568 open("/png/php/5.4.45/lib/php.ini", O_RDONLY) = 3