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.
In order to troubleshoot the problem, I deleted the .htaccess
files in order to access the setup page and install Magento. At this point, with an incorrect Apache configuration due to missing .htaccess
configuration, the homepage appears as plain HTML, with CSS styles omitted. The admin login page returns a 404 error.
I replaced the .htaccess
file by changing to the Magento working directory and issuing the command:
cp .htaccess.sample .htaccess
The apache error log read:
Invalid command 'php_value'
I commented out all lines of the .htaccess files containing php_value
and a new error was displayed:
Invalid command '<IfVersion'
Best Answer
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:
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: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: