---

- name: "Get PHP Version"
  ansible.builtin.shell:
    cmd: 'php -v | grep "PHP [0-9]." | sed -E "s/PHP ([0-9]\.[0-9]).*/\1/g;"'
  register: shell_php
  check_mode: no

- name: "Set variables"
  ansible.builtin.set_fact:
    php_version: "{{ shell_php.stdout }}"

- name: Apply specific PHP settings (apache)
  community.general.ini_file:
    path: "/etc/php/{{ php_version }}/apache2/conf.d/zzz-evolinux-custom.ini"
    section: ''
    option: "{{ item.option }}"
    value: "{{ item.value }}"
  notify: reload apache
  with_items:
  - {option: 'allow_url_fopen',   value: 'On'}
  - {option: 'disable_functions', value: ''}
  - {option: 'max_execution_time', value: '300'}
  - {option: 'memory_limit', value: '512M'}

- name: Apply specific PHP settings (cli)
  community.general.ini_file:
    path: "/etc/php/{{ php_version }}/cli/conf.d/zzz-evolinux-custom.ini"
    section: ''
    option: "{{ item.option }}"
    value: "{{ item.value }}"
  with_items:
  - {option: 'allow_url_fopen',   value: 'On'}
  - {option: 'apc.enable_cli', value: 'On'}
