2

I created a fresh install of Magento 2.2.2 on a debian server using php7.1 and mysql 5.7.

Once files were extracted, I was unable to access the setup wizard and received 500 errors from all pages.

Deleting the .htaccess files allows access to setup. Following successful installation, the homepage appears as plain html without CSS (because the .htaccess file is missing). The admin page returns a 404 error.

I then replaced the .htaccess files, copying .htaccess.sample files from their respective folders.

The apache error log showed the response Invalid command 'php_value', so I commented out all lines of the .htaccess files containing php_value.

The server then returned the error Invalid command '<IfVersion'.

<IfVersion fails because mod_version is not enabled in my server's Apache setup.

Other people have made the suggestion to use <IfModule mod_php7> to wrap the queries, but this seems excessive. Instead, I removed all queries and replaced them with the individual statements corresponding to my version of apache, as in my answer to this question.

  • @sv3n Why do you just make pointless edits? You do realise that stackexchange rep isn't actual currency? – Joshua Flood May 18 '18 at 16:40
  • 1
    I do not get any REP for edits since 2k REP. Just edited a tag and rolled back for some reasons. Nothing to worry about ;) – sv3n May 18 '18 at 17:53
  • Ok no worries. Apologies. Did read up on this in meta after commenting. – Joshua Flood May 18 '18 at 22:41
  • Hi after all this editing I am unable to sign in Admin – Shoban Poshala Nov 27 '19 at 6:01
  • @ShobanPoshala You made the edits that I explain in this question? That is not a solution. I was explaining that this is how I began troubleshooting and confirmed that mod_version is not enabled. If you are having issues with mod_version then please undo all the changes you made based on this question and follow the instructions in my answer. – Joshua Flood Nov 28 '19 at 11:11
5

This problem is caused when apache's mod_version module is not enabled. Unfortunately, my host does not allow me to enable this module and so I have devised the following workaround:

Step 1

Open [magento_root]/.htaccess with your favourite text editor.

You will notice, towards the end of the file, there are numerous entries following this format:

<Files composer.json>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files composer.lock>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
...

Step 2

The exact procedure here is dependent on the version of apache that your server is running. Mine runs 2.4, so I have removed all <IfVersion /> statements and replaced them with the content of their relevant clause, like so:

<Files composer.json>
    Require all denied
</Files>
<Files composer.lock>
    Require all denied
</Files>
...

This process must be repeated until there are no instances of <IfVersion /> remaining in the document.

Step 3

Open [magento_root]/pub/.htaccess with your favourite text editor and repeat the process laid out in step 2.

Note: In the event that this process has been carried out and then the apache version is changed (i.e. the server was running apache 2.2 and upgraded to 2.4), then files must be restored by replacing both edited files with the relevant .htaccess.sample, and following the above process from the beginning.

As mentioned in Erica Southworth's answer, the list I provide is not exhaustive, but it is all that is needed in order to recover basic functionality. Here is the list of all files containing IfVersion queries, for continuity:

app/.htaccess 
bin/.htaccess 
generated/.htaccess 
lib/.htaccess 
phpserver/.htaccess 
pub/.htaccess 
var/.htaccess 
vendor/.htaccess  
setup/config/.htaccess 
setup/performance-toolkit/.htaccess 
setup/src/.htaccess 
setup/view/.htaccess  
vendor/magento/magento2-base/.htaccess  
pub/media/customer/.htaccess 
pub/media/downloadable/.htaccess 
pub/media/import/.htaccess 
pub/media/theme_customization/.htaccess  
vendor/magento/magento2-base/vendor/.htaccess 
vendor/magento/magento2-base/var/.htaccess 
vendor/magento/magento2-base/pub/.htaccess 
vendor/magento/magento2-base/phpserver/.htaccess 
vendor/magento/magento2-base/lib/.htaccess 
vendor/magento/magento2-base/generated/.htaccess  
vendor/magento/magento2-base/dev/.htaccess 
vendor/magento/magento2-base/bin/.htaccess 
vendor/magento/magento2-base/app/.htaccess  
vendor/magento/magento2-base/setup/config/.htaccess 
vendor/magento/magento2-base/setup/performance-toolkit/.htaccess 
vendor/magento/magento2-base/setup/src/.htaccess 
vendor/magento/magento2-base/setup/view/.htaccess  
vendor/magento/magento2-base/pub/media/customer/.htaccess 
vendor/magento/magento2-base/pub/media/downloadable/.htaccess 
vendor/magento/magento2-base/pub/media/import/.htaccess 
vendor/magento/magento2-base/pub/media/theme_customization/.htaccess
3

Note you will need to remove the "IfVersion" commands from every .htaccess file in Magento, after the installation too. These are the files I had to modify with a fresh install Magento2 (2.4) and on the godaddy linux platform.

app/.htaccess 
bin/.htaccess 
generated/.htaccess 
lib/.htaccess 
phpserver/.htaccess 
pub/.htaccess 
var/.htaccess 
vendor/.htaccess  
setup/config/.htaccess 
setup/performance-toolkit/.htaccess 
setup/src/.htaccess 
setup/view/.htaccess  
vendor/magento/magento2-base/.htaccess  
pub/media/customer/.htaccess 
pub/media/downloadable/.htaccess 
pub/media/import/.htaccess 
pub/media/theme_customization/.htaccess  
vendor/magento/magento2-base/vendor/.htaccess 
vendor/magento/magento2-base/var/.htaccess 
vendor/magento/magento2-base/pub/.htaccess 
vendor/magento/magento2-base/phpserver/.htaccess 
vendor/magento/magento2-base/lib/.htaccess 
vendor/magento/magento2-base/generated/.htaccess  
vendor/magento/magento2-base/dev/.htaccess 
vendor/magento/magento2-base/bin/.htaccess 
vendor/magento/magento2-base/app/.htaccess  
vendor/magento/magento2-base/setup/config/.htaccess 
vendor/magento/magento2-base/setup/performance-toolkit/.htaccess 
vendor/magento/magento2-base/setup/src/.htaccess 
vendor/magento/magento2-base/setup/view/.htaccess  
vendor/magento/magento2-base/pub/media/customer/.htaccess 
vendor/magento/magento2-base/pub/media/downloadable/.htaccess 
vendor/magento/magento2-base/pub/media/import/.htaccess 
vendor/magento/magento2-base/pub/media/theme_customization/.htaccess  
  • Thanks Erica! I have added this list to my solution, for clarity. Could I ask, out of curiosity, which host/package are you using please? – Joshua Flood May 14 '18 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.