- name: 'Install common PHP dependencies (Debian <= 8)' apt: pkg: - 'php5-cli' - 'php5-curl' - 'php5-gd' - 'php5-intl' - 'php-soap' - 'php5-mcrypt' - 'php-mime-type' - 'php5-pgsql' - 'php5-sqlite' state: 'present' when: with_php|bool and ansible_lsb.major_release|int <= 8 tags: - 'web' - 'php' - name: 'Install common PHP dependencies (Debian >= 9, PHP version {{ php_version }})' apt: pkg: - 'php{{ php_version }}-cli' - 'php{{ php_version }}-curl' - 'php{{ php_version }}-gd' - 'php{{ php_version }}-intl' - 'php{{ php_version }}-soap' - 'php{{ php_version }}-mysql' - 'php{{ php_version }}-pgsql' - 'php{{ php_version }}-sqlite3' - 'php{{ php_version }}-zip' state: 'present' when: with_php|bool and ansible_lsb.major_release|int >= 9 tags: - 'web' - 'php' - name: 'Install common PHP dependencies (Debian >= 9, PHP < 7.2, PHP version {{ php_version }})' apt: pkg: - 'php{{ php_version }}-mcrypt' state: 'present' when: with_php|bool and ansible_lsb.major_release|int >= 9 and php_version|float < 7.2 tags: - 'web' - 'php' - name: 'Create PHP log directory' file: path: '/var/log/php' state: directory owner: 'root' group: 'root' mode: '0755' when: with_php|bool tags: - 'web' - 'php' - name: 'Install PHP configuration for syslog' template: src: '{{ item.src }}' dest: '{{ item.dest }}' owner: 'root' group: 'root' mode: '0644' with_items: - { src: 'rsyslog/php-errors.conf.j2', dest: '/etc/rsyslog.d/php-errors.conf' } - { src: 'logrotate/php-errors.j2', dest: '/etc/logrotate.d/php-errors' } notify: - 'Reload rsyslog for php' when: with_fpm|bool tags: - 'web' - 'php' - name: 'Install local PHP configuration overrides for php5-cli (Debian 8)' template: src: 'php/php-config-cli.ini.j2' dest: '/etc/php5/cli/conf.d/99-local-config.ini' owner: 'root' group: 'root' mode: '0644' when: with_php|bool and ansible_lsb.major_release|int == 8 tags: - 'web' - 'php' - name: 'Install local PHP configuration overrides for php{{ php_version }}-cli (Debian >= 9)' template: src: 'php/php-config-cli.ini.j2' dest: '/etc/php/{{ php_version }}/cli/conf.d/99-local-config.ini' owner: 'root' group: 'root' mode: '0644' when: with_php|bool and ansible_lsb.major_release|int >= 9 tags: - 'web' - 'php' - name: 'Install Apache2 module for php5' apt: pkg: - 'libapache2-mod-php5' state: 'present' notify: - 'Reload apache2' when: with_modphp5|bool tags: - 'web' - 'php' - name: 'Install Apache2 module for php{{ php_version }}' apt: pkg: - 'libapache2-mod-php{{ php_version }}' state: 'present' notify: - 'Reload apache2' when: with_modphp|bool tags: - 'web' - 'php' - name: 'Configure Apache2 modules for php-fpm{{ php_version }}' shell: a2dismod php{{ php_version }} mpm_prefork ; a2enmod mpm_event proxy_fcgi changed_when: False when: with_fpm|bool and with_apache2|bool notify: - 'Reload apache2' tags: - 'web' - 'php' - name: 'Configure Apache2 modules for modphp{{ php_version }}' shell: a2dismod mpm_event ; a2enmod mpm_prefork php{{ php_version }} changed_when: False when: with_modphp|bool notify: - 'Reload apache2' tags: - 'web' - 'php' - name: 'Install local PHP configuration (Debian < 8)' template: src: 'php/php-config-web.ini.j2' dest: '/etc/php5/conf.d/99-local-config.ini' owner: 'root' group: 'root' mode: '0644' notify: - 'Reload apache2' when: with_modphp5|bool and ansible_lsb.major_release|int < 8 tags: - 'web' - 'php' - name: 'Install local PHP configuration for Apache 2 (Debian 8)' template: src: 'php/php-config-web.ini.j2' dest: '/etc/php5/apache2/conf.d/99-local-config.ini' owner: 'root' group: 'root' mode: '0644' notify: - 'Reload apache2' when: with_modphp5|bool and ansible_lsb.major_release|int == 8 tags: - 'web' - 'php' - name: 'Install local PHP configuration for Apache 2 (Debian >= 9)' template: src: 'php/php-config-web.ini.j2' dest: '/etc/php/{{ php_version }}/apache2/conf.d/99-local-config.ini' owner: 'root' group: 'root' mode: '0644' notify: - 'Reload apache2' when: with_modphp|bool and ansible_lsb.major_release|int >= 9 tags: - 'web' - 'php' - name: 'Create system checks directory /etc/phpsyscheck' file: path: '/etc/phpsyscheck' state: 'directory' owner: 'root' group: 'root' mode: '0755' when: with_phpsyscheck|bool tags: - 'web' - 'php' - name: 'Install phpinfo system check' template: src: 'php/phpinfo.php' dest: '/etc/phpsyscheck/index.php' owner: 'root' group: 'root' mode: '0644' when: with_phpsyscheck|bool tags: - 'web' - 'php' - name: 'Install PHP APC extension (Debian <= 8)' apt: pkg: - 'php-apc' state: 'present' when: with_php_apc|bool and ansible_lsb.major_release|int <= 8 tags: - 'web' - 'php' - name: 'Install PHP APC extension (Debian >= 9)' apt: pkg: - 'php-apcu' state: 'present' when: with_php_apc|bool and ansible_lsb.major_release|int >= 9 tags: - 'web' - 'php' - name: 'Install php-apc system check' template: src: 'php/apc.php' dest: '/etc/phpsyscheck/apc.php' owner: 'root' group: 'root' mode: '0644' when: with_phpsyscheck|bool and with_php_apc|bool tags: - 'web' - 'php' - name: 'Install MySQL extension for PHP - native driver (Debian 8)' apt: pkg: - 'php5-mysqlnd' state: 'present' when: not with_php_mysql_legacy|bool and ansible_lsb.major_release|int == 8 tags: - 'web' - 'php' - name: 'Install MySQL extension for PHP (old driver)' apt: pkg: 'php5-mysql' state: 'present' when: with_php_mysql_legacy|bool tags: - 'web' - 'php' - name: 'Install PHPMyAdmin' apt: pkg: - 'phpmyadmin' state: 'present' when: with_phpmyadmin|bool tags: - 'web' - 'php' - name: 'Install PHPPgAdmin' apt: pkg: - 'phppgadmin' state: 'present' when: with_phppgadmin|bool tags: - 'web' - 'php' - name: 'Install FPM for PHP 5 (Debian <= 8)' apt: pkg: - 'php5-fpm' state: 'present' when: with_fpm|bool and ansible_lsb.major_release|int <= 8 tags: - 'web' - 'php' - name: 'Install FPM for PHP {{ php_version }} (Debian >= 9)' apt: pkg: - 'php{{ php_version }}-fpm' state: 'present' when: with_fpm|bool and ansible_lsb.major_release|int >= 9 tags: - 'web' - 'php' - name: 'Configure FPM for PHP 5 (Debian <= 8)' lineinfile: dest: '/etc/php5/fpm/php-fpm.conf' regexp: '^{{ item.key }}\s*=.*$' line: '{{ item.key }} = {{ item.value }}' insertafter: '^;{{ item.key }}' with_items: - { key: 'error_log', value: 'syslog' } - { key: 'log_level', value: 'warning' } - { key: 'emergency_restart_threshold', value: '100' } - { key: 'emergency_restart_interval', value: '5s' } - { key: 'rlimit_files', value: '262144' } - { key: 'events.mechanism', value: 'epoll' } - { key: 'include', value: '/etc/php5/fpm/pool.d/local-pool.cnf' } notify: - 'Reload FPM for PHP 5' when: with_fpm|bool and ansible_lsb.major_release|int <= 8 tags: - 'web' - 'php' - name: 'Configure FPM for PHP {{ php_version }} (Debian >= 9)' lineinfile: dest: '/etc/php/{{ php_version }}/fpm/php-fpm.conf' regexp: '^{{ item.key }}\s*=.*$' line: '{{ item.key }} = {{ item.value }}' insertafter: '^;{{ item.key }}' with_items: - { key: 'error_log', value: 'syslog' } - { key: 'log_level', value: 'warning' } - { key: 'emergency_restart_threshold', value: '100' } - { key: 'emergency_restart_interval', value: '5s' } - { key: 'rlimit_files', value: '262144' } - { key: 'events.mechanism', value: 'epoll' } - { key: 'include', value: '/etc/php/{{ php_version }}/fpm/pool.d/local-pool.cnf' } notify: - 'Reload FPM for PHP' when: with_fpm|bool and ansible_lsb.major_release|int >= 9 tags: - 'web' - 'php' - name: 'Install FPM pools configuration (legacy) for PHP 5 (Debian <= 8)' template: src: 'fpm/php5-fpm-pools.conf.j2' dest: '/etc/php5/fpm/pool.d/local-pool.cnf' owner: 'root' group: 'root' mode: '0644' notify: - 'Reload FPM for PHP 5' when: with_fpm|bool and not (fpm_pools is defined and fpm_pools) and ansible_lsb.major_release|int <= 8 tags: - 'web' - 'php' - name: 'Install FPM pools configuration (legacy) for PHP {{ php_version }} (Debian > 9)' template: src: 'fpm/php-fpm-pools-legacy.conf.j2' dest: '/etc/php/{{ php_version }}/fpm/pool.d/local-pool.cnf' owner: 'root' group: 'root' mode: '0644' notify: - 'Reload FPM for PHP' when: with_fpm|bool and not (fpm_pools is defined and fpm_pools) and ansible_lsb.major_release|int >= 9 tags: - 'web' - 'php' - name: 'Install FPM pools configuration for PHP {{ php_version }} (Debian > 9)' template: src: 'fpm/php-fpm-pools.conf.j2' dest: '/etc/php/{{ php_version }}/fpm/pool.d/local-pool.cnf' owner: 'root' group: 'root' mode: '0644' notify: - 'Reload FPM for PHP' when: with_fpm|bool and fpm_pools is defined and fpm_pools and ansible_lsb.major_release|int >= 9 tags: - 'web' - 'php' - name: 'Install local PHP configuration overrides for php5-fpm (Debian 8)' template: src: 'php/php-config-web.ini.j2' dest: '/etc/php5/fpm/conf.d/99-local-config.ini' owner: 'root' group: 'root' mode: '0644' when: with_fpm|bool and ansible_lsb.major_release|int == 8 tags: - 'web' - 'php' - name: 'Install local PHP configuration overrides for php{{ php_version }}-fpm (Debian >= 9)' template: src: 'php/php-config-web.ini.j2' dest: '/etc/php/{{ php_version }}/fpm/conf.d/99-local-config.ini' owner: 'root' group: 'root' mode: '0644' notify: - 'Reload FPM for PHP' when: with_fpm|bool and ansible_lsb.major_release|int >= 9 tags: - 'web' - 'php' - name: 'Install Apache2 config files for PHP FPM' template: src: 'fpm/apache2/fpm-pool.conf.j2' dest: '/etc/apache2/conf-available/fpm-pool.conf' owner: 'root' group: 'root' mode: '0644' when: with_fpm|bool and with_apache2|bool tags: - 'web' - 'php' - name: 'Install Nginx config files for PHP FPM (fpm servers pool)' template: src: 'fpm/nginx/fpm-pool.conf.j2' dest: '/etc/nginx/conf.d/fpm-pool.conf' owner: 'root' group: 'root' mode: '0644' notify: - 'Reload nginx' when: with_fpm|bool and with_nginx|bool tags: - 'web' - 'php' - name: 'Install Nginx config files for PHP FPM (fpm fastcgi config)' template: src: 'fpm/nginx/fastcgi_pass_fpm.j2' dest: '/etc/nginx/fastcgi_pass_fpm' owner: 'root' group: 'root' mode: '0644' notify: - 'Reload nginx' when: with_fpm|bool and with_nginx|bool tags: - 'web' - 'php' - name: 'Ensure FPM for PHP 5 is running (Debian <= 8)' service: name: 'php5-fpm' state: 'started' when: with_fpm|bool and ansible_lsb.major_release|int <= 8 tags: - 'web' - 'php' - name: 'Ensure FPM for PHP {{ php_version }} is running (Debian >= 9)' service: name: 'php{{ php_version }}-fpm' state: 'started' when: with_fpm|bool and ansible_lsb.major_release|int >= 9 tags: - 'web' - 'php' # vim: ft=yaml.ansible