diff --git a/tasks/a2mod.yml b/tasks/a2mod.yml
index a297037dfe54ac147b7d91cbee5b14ad72307412..4193908436b006855de8269811e947b3ecc46497 100644
--- a/tasks/a2mod.yml
+++ b/tasks/a2mod.yml
@@ -32,7 +32,7 @@
           - "libapache2-mod-php{{ apache_php_version }}"
         state: absent
         update_cache: false
-      when: '"apache_phpfpm_mod" in apache_mods_disabled'
+      when: ( apache_php ) and ( "apache_phpfpm_mod" in apache_mods_disabled )
 
     - name: Disable modules
       apache2_module:
@@ -83,7 +83,7 @@
           - "libapache2-mod-php{{ apache_php_version }}"
         state: present
         update_cache: false
-      when: '"apache_phpfpm_mod" in apache_mods_enabled'
+      when: ( apache_php ) and ( "apache_phpfpm_mod" in apache_mods_enabled )
 
     - name: Apache modules enabled
       apache2_module:
diff --git a/tasks/checks.yml b/tasks/checks.yml
index f69736aeacccf950b46361a20bb985b1d1b1de0b..e84675c1c634029c259d0aa98efb0e6150285ce8 100644
--- a/tasks/checks.yml
+++ b/tasks/checks.yml
@@ -180,11 +180,15 @@
       when: apache_version is version('2.4.41', '>=')
 
     - name: Check if phpquery is installed
-      shell: which phpquery || echo absent
+      shell: which phpquery || echo ABSENT
       check_mode: false
       register: apache_phpquery_path
       changed_when: '"phpquery" not in apache_phpquery_path.stdout'
 
+    - name: Set the apache_php variable to true or false
+      set_fact:
+        apache_php: "{% if apache_phpquery_path.stdout == 'ABSENT' %}false{% else %}true{% endif %}"
+
     - name: Check PHP version
       block:
 
@@ -210,7 +214,7 @@
               - "apache_phpfpm_conf: {{ apache_phpfpm_conf }}"
             verbosity: 2
 
-      when: ( apache_phpquery_path is defined ) and ( apache_phpquery_path.stdout == "/usr/sbin/phpquery" )
+      when: ( apache_php is defined ) and ( apache_php )
 
     - name: Check loaded modules
       block:
diff --git a/templates/localhost.conf.j2 b/templates/localhost.conf.j2
index 00a32cb19c32026e2d4a70de88a16bfe380eb789..08484b283f7abb6454906768a29f16af5ffc898b 100644
--- a/templates/localhost.conf.j2
+++ b/templates/localhost.conf.j2
@@ -21,7 +21,7 @@
     </Location>
   </IfModule>
 {% endif %}
-{% if "proxy_fcgi" in apache_mods_enabled %}
+{% if apache_php and if "proxy_fcgi" in apache_mods_enabled %}
   <Location /status>                                                       
     SetHandler "proxy:unix:/run/php/php{{ apache_php_version }}-fpm.sock|fcgi://localhost/"
     Require host localhost 127.0.0.1 ::1
@@ -35,7 +35,7 @@
     AllowOverride AuthConfig Indexes FileInfo Limit
     Require host localhost 127.0.0.1 ::1
 {% if apache_mods_enabled is defined %}
-{% if apache_phpfpm_mod is defined and apache_phpfpm_mod in apache_mods_enabled %}
+{% if apache_php and if apache_phpfpm_mod is defined and apache_phpfpm_mod in apache_mods_enabled %}
     <IfModule php7_module>
       php_admin_value doc_root /var/www/localhost
       php_admin_value open_basedir /var/www/localhost/:/tmp/:/usr/share/php/
@@ -44,7 +44,7 @@
       </FilesMatch>
     </IfModule>
 {% endif %}
-{% if "proxy_fcgi" in apache_mods_enabled %}
+{% if apache_php and if "proxy_fcgi" in apache_mods_enabled %}
     # https://wiki.apache.org/httpd/PHP-FPM#Proxy_via_handler
     <IfModule proxy_fcgi_module>
       <IfModule setenvif_module>