From 8d760fee482b16713152d61ea03b32c7c498468f Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Tue, 10 May 2016 14:44:03 +0200
Subject: [PATCH] Prepare for Ubuntu 16.04 with PHP 7

---
 defaults/main.yml                  |  5 ++--
 handlers/main.yml                  |  9 -------
 meta/main.yml                      |  4 ++++
 tasks/oci.yml                      |  2 +-
 tasks/php.yml                      | 38 +++++++++++++++++-------------
 tasks/php53.yml                    |  4 ++--
 templates/etc-init-d-php53-fpm     |  4 ++--
 templates/etc-php5-apache2-php.ini |  2 +-
 8 files changed, 35 insertions(+), 33 deletions(-)
 delete mode 100644 handlers/main.yml
 create mode 100644 meta/main.yml

diff --git a/defaults/main.yml b/defaults/main.yml
index fab78fd..3974485 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,4 +1,3 @@
-php_called_from_apache: false
 php_install_redis: true
 php_repositories: []
 php_packages:
@@ -19,9 +18,11 @@ php_packages:
   - php5-xmlrpc
   - imagemagick
 
+php_base_dir: 'php5'
+php_conf_dir: 'conf.d'
+
 php_allow_call_time_pass_reference: 'on'
 php_browscap: false
-php_conf_dir: 'conf.d'
 php_date_timezone: 'Europe/Berlin'
 php_display_errors: 'Off'
 php_display_startup_errors: 'Off'
diff --git a/handlers/main.yml b/handlers/main.yml
deleted file mode 100644
index 37c5633..0000000
--- a/handlers/main.yml
+++ /dev/null
@@ -1,9 +0,0 @@
----
-# file: roles/php/handlers/php.yml
-
-- name: "PHP | Restart Apache"
-  debug: msg="Need to restart Apache server"
-  when: php_called_from_apache
-  changed_when: php_called_from_apache
-  notify:
-    - "Apache | Restart Apache"
diff --git a/meta/main.yml b/meta/main.yml
new file mode 100644
index 0000000..b974baf
--- /dev/null
+++ b/meta/main.yml
@@ -0,0 +1,4 @@
+---
+
+dependencies:
+  - { role: apache }
diff --git a/tasks/oci.yml b/tasks/oci.yml
index 235043d..9ea95ef 100644
--- a/tasks/oci.yml
+++ b/tasks/oci.yml
@@ -8,7 +8,7 @@
 - name: "PHP | OCI | Enable OCI for PHP"
   copy:
     content='extension={{ item }}.so'
-    dest=/etc/php5/{{ php_conf_dir }}/{{ item }}.ini
+    dest=/etc/{{ php_base_dir }}/{{ php_conf_dir }}/{{ item }}.ini
     owner=root
     group=root
     mode=0644
diff --git a/tasks/php.yml b/tasks/php.yml
index 7ff7eab..6d93576 100644
--- a/tasks/php.yml
+++ b/tasks/php.yml
@@ -13,18 +13,25 @@
     state=installed
   with_items: '{{ php_packages }}'
   notify:
-    - "PHP | Restart Apache"
+    - "Apache | Restart Apache"
+
+- name: "PHP | Ensure Apache config directory"
+  file:
+    dest=/etc/{{ php_base_dir }}/apache2
+    state=directory
+    owner=root
+    group=root
+    mode=0755
 
 - name: "PHP | Configuration file, php.ini"
   template:
     src=etc-php5-apache2-php.ini
-    dest=/etc/php5/apache2/php.ini
+    dest=/etc/{{ php_base_dir }}/apache2/php.ini
     owner=root
     group=root
     mode=0644
-  when: not php_called_from_apache
   notify:
-    - "PHP | Restart Apache"
+    - "Apache | Restart Apache"
 
 - include: php53.yml
   when: php_version|default('5.5') == '5.3'
@@ -36,33 +43,32 @@
     owner=root
     group=root
     mode=0644
-  when: not php_called_from_apache
   notify:
-    - "PHP | Restart Apache"
+    - "Apache | Restart Apache"
 
 - name: "PHP | Cache configuration file, apc.ini"
   template:
     src=etc-php5-conf-d-apc.ini
-    dest=/etc/php5/{{ php_conf_dir }}/apc.ini
+    dest=/etc/{{ php_base_dir }}/{{ php_conf_dir }}/apc.ini
     owner=root
     group=root
     mode=0644
   notify:
-    - "PHP | Restart Apache"
+    - "Apache | Restart Apache"
 
 - name: "PHP | Cache configuration file, opcache.ini"
   template:
     src=etc-php5-conf-d-opcache.ini
-    dest=/etc/php5/{{ php_conf_dir }}/opcache.ini
+    dest=/etc/{{ php_base_dir }}/{{ php_conf_dir }}/opcache.ini
     owner=root
     group=root
     mode=0644
   notify:
-    - "PHP | Restart Apache"
+    - "Apache | Restart Apache"
 
 - name: "PHP | Create extra directory for browscap"
   file:
-    dest=/etc/php5/apache2/extra
+    dest=/etc/{{ php_base_dir }}/apache2/extra
     state=directory
     owner=root
     group=root
@@ -71,12 +77,12 @@
 - name: "PHP | browscap.ini"
   copy:
     src=browscap.ini
-    dest=/etc/php5/apache2/extra/browscap.ini
+    dest=/etc/{{ php_base_dir }}/apache2/extra/browscap.ini
     owner=root
     group=root
   when: php_browscap
   notify:
-    - "PHP | Restart Apache"
+    - "Apache | Restart Apache"
 
 - name: "PHP | Enable PHP modules"
   shell: php5enmod {{ item }}
@@ -84,9 +90,9 @@
     - mcrypt
     - imap
     - imagick
-  when: php_conf_dir == 'mods-available'
+  when: php_version|default('5.5') != '7' and php_conf_dir == 'mods-available'
   notify:
-    - "PHP | Restart Apache"
+    - "Apache | Restart Apache"
 
 - name: "PHP | Create htdocs directory for apc status"
   file:
@@ -109,7 +115,7 @@
   ignore_errors: yes
   changed_when: oci_available.stdout != '/usr/lib/php5/20090626/pdo_oci.so'
   notify:
-    - "PHP | Restart Apache"
+    - "Apache | Restart Apache"
 
 - include: oci.yml
   when: repository is defined and php_needs_oci8 and oci_available.stdout != '/usr/lib/php5/20090626/pdo_oci.so'
diff --git a/tasks/php53.yml b/tasks/php53.yml
index 6492b42..7e0caf4 100644
--- a/tasks/php53.yml
+++ b/tasks/php53.yml
@@ -8,7 +8,7 @@
     dest='{{ item }}'
     state='directory'
   with_items:
-    - '/etc/php5/fpm/pool.d/'
+    - '/etc/{{ php_base_dir }}/fpm/pool.d/'
 
 - name: "Check PHP 5.3 Requirement"
   shell: php --version
@@ -134,7 +134,7 @@
 - name: "Create PHP53 INI Files"
   template:
     src='etc-php5-apache2-php.ini'
-    dest='/etc/php5/{{ item }}/php.ini'
+    dest='/etc/{{ php_base_dir }}/{{ item }}/php.ini'
     owner='root'
     group='root'
     mode='644'
diff --git a/templates/etc-init-d-php53-fpm b/templates/etc-init-d-php53-fpm
index 773d390..5a7b54c 100644
--- a/templates/etc-init-d-php53-fpm
+++ b/templates/etc-init-d-php53-fpm
@@ -14,8 +14,8 @@ prefix=/usr/local
 exec_prefix=${prefix}
 
 php_fpm_BIN=${exec_prefix}/sbin/php-fpm
-php_fpm_CONF=/etc/php5/fpm/php-fpm.conf
-php_fpm_INI=/etc/php5/fpm/php.ini
+php_fpm_CONF=/etc/{{ php_base_dir }}/fpm/php-fpm.conf
+php_fpm_INI=/etc/{{ php_base_dir }}/fpm/php.ini
 php_fpm_PID=/var/run/php5-fpm.pid
 
 php_opts="-c $php_fpm_INI --fpm-config $php_fpm_CONF --pid $php_fpm_PID"
diff --git a/templates/etc-php5-apache2-php.ini b/templates/etc-php5-apache2-php.ini
index c23cca5..16bb5fd 100644
--- a/templates/etc-php5-apache2-php.ini
+++ b/templates/etc-php5-apache2-php.ini
@@ -1349,7 +1349,7 @@ bcmath.scale = 0
 ; http://php.net/browscap
 ;browscap = extra/browscap.ini
 {% if php_browscap %}
-browscap = /etc/php5/apache2/extra/browscap.ini
+browscap = /etc/{{ php_base_dir }}/apache2/extra/browscap.ini
 {% endif %}
 
 [Session]
-- 
GitLab