11

Is it possible to create separate php.ini files for php (cli) and php-fpm, like it is possible on debian and ubuntu with two folders /etc/php/7.0/cli and /etc/php/7.0/fpm?

I will be also cool if I can load independent modules with a conf.d directory for each subsystem.

Has anyone an idea how can I configure it separately?

I also tried to use the structure like it is configured in ubuntu 16.04 without success.

Fiete
  • 331
  • 2
  • 9

2 Answers2

12

I have found a few tweaks to solve my problem.

First: load a separate php.ini files:

A user in a arch linux forum posted this from the man php page:

FILES
   php-cli.ini    The configuration file for the CLI version of PHP.

   php.ini        The standard configuration file will only be used when php-cli.ini cannot be found.

If I creating a /etc/php/php-cli.ini file only this file will be loaded and not /etc/php/php.ini with the php cli command. php-fpm is still loading the /etc/php/php.ini.

Second: load different module configurations:

I have found in the php documentation the PHP_INI_SCAN_DIR environment variable. Therefore I have moved the /usr/lib/systemd/system/php-fpm.service file to /etc/systemd/system/php-fpm.service and added the following configuration to the service file:

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=notify
Environment="PHP_INI_SCAN_DIR=/etc/php/fpm/conf.d" ; <-- I have added this line
PIDFile=/run/php-fpm/php-fpm.pid
ExecStart=/usr/bin/php-fpm --nodaemonize --fpm-config /etc/php/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

After restarting/reloading the services, php-fpm loads only the files from /etc/php/fpm/conf.d and no longer from /etc/php/conf.d. This allows me to configure cli and fpm separately.

Perhaps this is not the best solution but I fits to my usecase. If everyone have a better solution, don't hesitate to post your answer!

Fiete
  • 331
  • 2
  • 9
  • 1
    This second approach is extremely useful for debugging, i.e. you create suffixed copies of the php-fpm service and conf files/dirs, specify a separate fpm config as you have, optionally specify a different ini with `--php-ini`, then load the xdebug only in the second service. Of course, the second service needs to run on a different port/socket. I set `Environment="PHP_INI_SCAN_DIR=/etc/php-debugger.d:"` in my service file, the colon added so it loads all the default modules in addition to the xdebug one I copied to the `debugger.d` dir. – Walf Apr 16 '18 at 05:42
3

You can always do this for the cli version:

php -c /path/to/your/php.ini

and leave the defaults with the ones served over php-fpm. Or even better, add this to your login scripts

# ~/.bashrc
# aliases and personal functions

# PHP source personal ini
alias php='php -c /path/to/your/php.ini'

# colorize ls
alias ls='ls --color'
...

It would have been better if you had stated which version(s) you are using

  • nice idea, but not exactly what I'm looking for. Perhaps if there no other way. Thanks. – Fiete Oct 07 '16 at 18:13
  • well, maybe there is, please do share what version of php, php-fpm and your basic setup (are you using nginx, apache etc). How you have setup php-fpm. maybe from there, we can be helpful – the_architecht Oct 07 '16 at 23:22