--- - name: Install PHP, PHP-FPM, and common extensions apt: name: - php - php-fpm - php-cli - php-mysql - php-curl - php-gd - php-mbstring - php-xml - php-zip state: present update_cache: yes - name: Enable Apache modules for PHP-FPM command: a2enmod {{ item }} loop: - proxy_fcgi - setenvif - php{{ php_version }} # or php8.1 depending on your distro notify: Reload Apache ignore_errors: yes # in case some modules aren't available - name: Ensure PHP-FPM service is running service: name: php{{ php_version }}-fpm state: started enabled: yes when: php_version is defined - name: Deploy custom PHP-FPM pool config template: src: www.conf.j2 dest: /etc/php/{{ php_version }}/fpm/pool.d/www.conf owner: root group: root mode: '0644' notify: Restart PHP-FPM