As any error appearing on any website, Magento 2 internal server error 500 influences your customer experience, traffic, and conversions. Though sometimes it can disappear after you reload the page, you should take steps to eliminate it immediately, so it doesn't influence your store traffic for hours.

It is one of the most common Magento errors. So before we get to the solution to fix 500 internal server errors in Magento 2, you should know what it is. 

What is Internal Server Error 500 in Magento 2?

Magento internal server error is a general HTTP status code that appears when you follow the correct URL or click on a website link and request a page from the server. Something goes wrong and the server can't return the requested page and doesn't know what the issue is. 

Magento 2 Internal Server Error

Since the server doesn't know anything about the issues and displays only Internal Server Error 500, you should access the server error logs and check for more information about this issue.

And here are the most common reasons for Internal server errors to appear.

Reasons of Magento 2 500 Internal Server Error

Fixing the Internal Server Error in Magento doesn't take as much as finding the cause of the problem, since there are quite a few reasons why it appears:

  • Permission Issue
  • Memory Limit
  • Missing Modules
  • Issues in .htaccess File
  • Third-party Extension

How to Fix Magento 2 Internal Server Error?

Based on the causes of this issue, there are the following solutions. However, before taking any actions, enable developer mode and uncomment the following line

#ini_set('display_errors', 1);

in the app/bootstrap.php file to easily debug Magento and get the detailed exceptions in the error log.

Solution #1 Change File Permissions

Magento Internal Server issue most commonly appears when you try to access the Magento admin panel or the connect manager while the Magento permission files are not configured correctly.

Default permission of the index files is 664 after Magento installation which should be 644.

To change the default file permissions from 664 to 644, go to the index.php file in the Magento root and run the following commands.

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find ./var -type d -exec chmod 777 {} \;
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
chmod u+x bin/magento

Solution #2 Increase Memory Limit

Magento platform requires certain system capabilities to work correctly. This does include certain PHP memory limits. Usually, Magento hosting providers set a default memory limit to e.g. 20MB or 60 MB which is not enough for Magento.  

To fix Magento internal server error 500, you need to increase the php_memory_limit value to 756M in php.ini or .htaccess files.

For that:

  • Log in to your website server using SSH.
  • Find the folder with the php.ini file and open it via the vi editor.
  • Add the following line to it
memory_limit = 756M
  • Or increase it if the value is too low.

Otherwise:

  • Log in to your website server using SSH.
  • Add the following lines to the .htaccess file.
<IfModule mod_php5.c>
php_value memory_limit 256M
</IfModule>

Solution #3 Rename .htaccess File

Configuration of the .htaccess file is also very important since any errors, typos can cause issues, including Magento 2 500 internal server error. Issues in the .hraccess file appear when you install plugins, patches, or themes and require correct configurations.

Try removing or renaming the .htaccess file to see if the issue will be fixed. 

Solutions #4 Disable Third-party Extensions

Internal Server Error in Magento might appear after you install third-party Magento extensions or upgrade some of them. It is usually a conflict between the new extension or version with the existing modules on your store. 

Run the following command to disable the extension: 

 php bin/magento mod:disable VenorName_ModuleName

Once you run it, contact the vendor to get the details and the fix.

Solution #5 Disable Maintenance Mode

When you enable maintenance mode maintenance.flag file is placed in the Magento root folder. This changes the index.php file permission to 666 which web browsers can't execute. 

Run the following command to remove the maintenance.flag file and change the permission in index.php to 755.

php bin/magento maintenance:disable

These are the main reasons and solutions for the Magento 2 Internal Server Error that are going to help you sort it out.

Sooner or later every Magento developer comes across it while troubleshooting Magento. However, once you read this article, you should be ready to identify the reason and choose one of the above-mentioned solutions.