php.ini: which one?

php

Solution

Generally speaking, the `cli/php.ini` file is used when the PHP binary is called from the command-line. You can check that running `php --ini` from the command-line.

`fpm/php.ini` will be used when PHP is run as FPM -- which is the case with an nginx installation. And you can check that calling `phpinfo()` from a php page served by your webserver.

`cgi/php.ini`, in your situation, will most likely not be used.

Using two distinct `php.ini` files (one for CLI, and the other one to serve pages from your webserver) is done quite often, and has one main advantages : it allows you to have different configuration values in each case.

Typically, in the `php.ini` file that's used by the web-server, you'll specify a rather short `max_execution_time` : web pages should be served fast, and if a page needs more than a few dozen seconds (30 seconds, by default), it's probably because of a bug -- and the page's generation should be stopped. On the other hand, you can have pretty long scripts launched from your crontab (or by hand), which means the `php.ini` file that will be used is the one in `cli/`. For those scripts, you'll specify a much longer `max_execution_time` in `cli/php.ini` than you did in `fpm/php.ini`.

`max_execution_time` is a common example ; you could do the same with several other configuration directives, of course.

Problem

I moved from my old apache to nginx and php 5.3.10. And when I tried to modify php.ini to suit my needs, I found there are 3 of them: ``` $ locate php.ini /etc/php5/cgi/php.ini /etc/php5/cli/php.ini /etc/php5/fpm/php.ini ``` Which one should I edit?

Original source