# roles/php/tasks/main.yml
---
- name: Add repository for PHP 5.6 (Ubuntu/Debian)
  ansible.builtin.apt_repository:
    repo: ppa:ondrej/php
    state: present
    update_cache: yes
  when: ansible_os_family == "Debian"

- name: Restart Apache to apply PHP configuration changes
  service:
    name: apache2  # Use 'httpd' for CentOS/Red Hat
    state: restarted

- name: Install PHP 5.6 and required extensions (Ubuntu/Debian)
  apt:
    name: 
      - php5.6
      - php5.6-cli
      - php5.6-common
      - php5.6-curl
      - php5.6-mbstring
      - php5.6-xml
      - php5.6-mysql
    state: present
  when: ansible_os_family == "Debian"
  notify: 
    - check php

- name: Enable display_errors in PHP 5.6
  lineinfile:
    path: /etc/php/5.6/apache2/php.ini  # Adjust path if you're using a different web server or OS
    regexp: '^display_errors = .*'
    line: 'display_errors = On'
    state: present
    backup: yes
  when: display_php_errors is defined and display_php_errors | bool