ansible-role-php icon indicating copy to clipboard operation
ansible-role-php copied to clipboard

Separate templates for CLI php.ini?

Open jonpugh opened this issue 7 years ago • 15 comments

I think we should figure out a way to have either separate templates or separate variables for php.ini for CLI.

For example often there will be no memory limit for CLI.

Not sure the best approach here, but perhaps the CLI php.ini is an exception and we should add a separate template and variables for it?

Just a thought!

jonpugh avatar Jul 08 '16 20:07 jonpugh

I'd also like to only override the default php.ini with a simple include -- https://github.com/geerlingguy/ansible-role-php/pull/97

maybe allow php_cli_[conf var] or php_fpm_[conf_var] or in this case --

php_cli_memory_limit would override php_memory_limit for cli.

thom8 avatar Jul 10 '16 13:07 thom8

or even easier an override var per SAPI like

php_cli_conf:
  memory_limit: -1

could create /etc/php/7.0/cli/conf.d/zzz_overrides.ini on Ubuntu.

thom8 avatar Jul 10 '16 13:07 thom8

Might try to tackle a PR for this over the next week or so but would need to know the best approach for overriding php.ini config for CLI on CentOS.

http://www.php.net/manual/en/configuration.file.php

Is using a /etc/php-cli.ini the recommended way? would prefer not to duplicate all config but only set overrides.

thom8 avatar Jul 30 '16 23:07 thom8

It looks like downstream issue https://github.com/geerlingguy/ansible-role-php-xdebug/issues/34 will need this as well.

On CentOS/RHEL, where config is typically much simpler (e.g. don't have some crazy set of potentially dozens of config files), you would generally have one CLI config file, and /etc would be where it resides (next to /etc/php.ini).

geerlingguy avatar Aug 01 '16 16:08 geerlingguy

From what I can tell there's no standard way to set only overrides for a single SAPI in CentOS, so whilst it's crazy to have dozens of config files they do provide an easy way to manage overrides.

In this case I'd only need to create and single conf file with 2 lines rather than duplicating the whole php conf file.

/etc/php/[php_version]/cli/conf.d/zzz_overrides.ini

php_memory_limit=-1
xdebug.default_enable=0

thom8 avatar Aug 02 '16 06:08 thom8

php --ini

CentOS 7 (PHP7)

Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed:      /etc/php.d/...
...

Ubuntu 14.04 (PHP7)

Configuration File (php.ini) Path: /etc/php/7.0/cli
Loaded Configuration File:         /etc/php/7.0/cli/php.ini
Scan for additional .ini files in: /etc/php/7.0/cli/conf.d
Additional .ini files parsed:      /etc/php/7.0/cli/conf.d/...
...

CentOS does support php-cli.ini but the issue is any config will still be overridden by /etc/php.d/.. so in the case of xdebug if we set xdebug.default_enable=0 in php-cli.ini it could be overridden in /etc/php.d/xdebug.ini so you could only disable xdebug globally not only in CLI.

We probably just need to have different configuration tasks for each OS..

@geerlingguy I'm happy to put together a PR but would it be accepted if this role primarily supports RHEL?

https://github.com/geerlingguy/ansible-role-php/issues/93#issuecomment-199838746

thom8 avatar Aug 04 '16 00:08 thom8

I'm fairly new to ansible, but wouldn't it be possible to use this role twice and pass two different variable files to it to configure fpm and cli differently? See my thinking below:

- host: xyz
  roles:
    - role: geerlingguy.php
      include_vars: cli.yml
    - role: geerlingguy.php
      include_vars: fpm.yml

where cli.yml is something like:

php_conf_paths:
  - /etc/php/7.0/cli

php_extension_conf_paths:
  - /etc/php/7.0/cli/conf.d

php_expose_php: "On"
php_memory_limit: "-1"

php_session_save_handler: "files"
php_session_save_path: ""

and something similar for fpm setting the conf_paths appropriately. I suppose its not optimal because of some redundant duplicated tasks.

jradtilbrook avatar Jan 11 '17 11:01 jradtilbrook

@jradtilbrook you solution should work if you're not also using geerlingguy.php-versions, because it sets php_conf_paths with set_fact which overrides most other ways to set a variable (see the docs). So I had to use set_fact to ensure my second run off geerlingguy.php got the correct variables:

- hosts: xyz
  roles:
    - geerlingguy.php-versions
    - geerlingguy.php

- hosts: xyz
  pre_tasks:
    - name: Override php cli config
      set_fact: "{{ item.key }}={{item.value }}"
      with_dict:
        php_conf_paths: [/etc/php/7.2/cli]
        php_memory_limit: -1
  roles:
    - geerlingguy.php

You're right it is a bit gross, since the roll is being run twice it kind of breaks idempotency. But I'm only running it once when I build an AMI/vagrant box so I'm not too worried.

ndench avatar Sep 13 '18 08:09 ndench

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar Mar 06 '20 03:03 stale[bot]

I'm currently using the workaround @ndench proposed. It's not a perfect solution but it works for now.

colinodell avatar Mar 06 '20 12:03 colinodell

This issue is no longer marked for closure.

stale[bot] avatar Mar 06 '20 12:03 stale[bot]

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar Jun 04 '20 12:06 stale[bot]

Bumping this out of the stale state as this is still something I have to work around and would find valuable to have.

colinodell avatar Jun 04 '20 14:06 colinodell

This issue is no longer marked for closure.

stale[bot] avatar Jun 04 '20 14:06 stale[bot]

Please review my just-submitted MR, which should work for Debian-based OSes at least: #347.

colans avatar Oct 08 '21 22:10 colans