How to fix Magento 2 500 internal server error
In the following article, we shed light on how to fix the 500 internal server error in Magento 2. The problem affects the overall e-commerce experience of a storefront, so it is necessary to fix it as fast as possible. Numerous users ask for help on various forums and community resources, and below, we explore the best resolutions!
According to
1 2 3 4 5 |
rm -rf var/page_cache var/cache var/composer_home var/generation var/di var/view_preprocessed php bin/magento setup:upgrade php bin/magento setup:static-content:deploy php bin/magento indexer:reindex php bin/magento indexer:clean |
Next, it is necessary to give correct permissions to your directories.
1 2 3 4 |
All directories have 770 permissions. 770 permissions give full control (that is, read/write/execute) to the owner and to the group and no permissions to anyone else. All files have 660 permissions. 660 permissions mean the owner and the group can read and write but other users have no permissions. |
Try to run these commands in SSH and your permissions should be sorted:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
cd <your Magento install dir> find . -type f -exec chmod 644 {} \; // 644 permission for files find . -type d -exec chmod 755 {} \; // 755 permission for directory find ./var -type d -exec chmod 777 {} \; // 777 permission for var folder find ./pub/media -type d -exec chmod 777 {} \; find ./pub/static -type d -exec chmod 777 {} \; chmod 777 ./app/etc chmod 644 ./app/etc/*.xml chown -R :<web server group> . chmod u+x bin/magento |
According to
1 2 |
/var/log/httpd/ -> centos, archlinux ... /var/log/apache2/ -> debian, ubuntu … |
At the same time,
1 |
php bin/magento setup:static-content:deploy |
Firstly, you need to make sure that LoadModule version_module modules/mod_version.so is loaded from httpd.conf file. This will help to resolve the invalid command ‘<IfVersion’, which is perhaps misspelled or defined by a module not included in the server configuration error.
Secondly, the author insists on setting the following variable values:
1 2 3 |
max_execution_time = 1800 max_input_time = 1800 memory_limit = 1024M |
Thirdly, you can create a virtual host. Add the following code to your file path: D:\wamp64\bin\apache\apache2.4.18\conf\extra\httpd-vhosts.conf
Note that your path depends on your installation:
1 2 3 4 5 6 7 8 9 |
<VirtualHost *:80> ServerName demomage222 ServerAlias www.demomage222.com DocumentRoot D:/wamp64/www/mage222 <Directory "/"> Options +Indexes +FollowSymLinks +MultiViews AllowOverride All Require local </Directory> |
Next, you should make an entry in the host file following this example:
1 |
127.0.0.1 www.demomage222.com |
here
1 2 |
C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\etc\hosts |
Now, let’s take a look at another example of the “500” error.
To fix Magento 500 internal server error, navigate to the Magento directory on your server:
1 |
cd /var/www/magento |
Next, set the permissions via the following command:
1 |
find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \; && find var vendor pub/static pub/media app/etc -type d -exec chmod g+w {} \; && chmod u+x bin/magento |
If the aforementioned command doesn’t help, go to cd /var/www/magento/var/ and type ls -al. You will see if the permissions on all files are properly set. Note that your web server should be able to write/delete all files.
That’s it! Now, you know how to fix the 500 server error in Magento 2. For further useful tips, check our Cookbook.