Magento will end support for Magento 1 by June 2020. That’s why many users are migrating their Magento 1 store to Magento 2 store. However, Magento 1 to Magento 2 migration can be a challenging project. During the migration process, you can come up against issues since this procedure is extremely unpredictable and related to several customizations.
Magento has developed a Magento Data Migration Tool to assist you with transferring your data. It will help you recognize the differences in the database structure between Magento 1 and Magento 2 databases. Most of these differences are declared in map files. The Data Migration Tool uses map files to transform data into the Magento 2 store. When differences are not declared in map files, then the Data Migration Tool displays an error message and stops running.
Today, we will learn How to fix 500 internal server error in Magento 2?
Contents
When do you get 500 internal server error in Magento 2
You have a problem with you website use magento 2. This is “500 internal server error” problem. So, when do you get this error?
Today, we also show you some cases when you get this issue:
- Update, install, or remove a component such as theme, patches, plugins,… on Magento website
- After migrating the site to another server
- After uploading data to the server locally, change some files and some tables in database.
How to fix 500 internal server error in Magento 2
Enable Developer mode
To displaying your error exactly, you have to Enable Developer Mode before doing anything. This mode allows you to debug Magento, which means it allows you to see detail exceptions on your error page, not just messages like “There has been an error processing your request”, “Magento exception printing is disabled by default for security reasons”, or “Magento 500 Internal Server Error”.
Fist way, you can enable it from the CLI:
1 |
bin/magento deploy:mode:set developer |
Another way, we can enable developer mode in the env.php file:
- Go to app/etc/ and open env.php
- And change current application mode by ‘MAGE_MODE’ => ‘default’ to ‘MAGE_MODE’ => ‘developer’
Or if you use Apache, we can change developer mode in your .htaccess file:
1 |
SetEnv MAGE_MODE "developer" |
Then, please flush the cache.
If you are using NginX as the web server, changing htaccess file won’t work, you need to add set $MAGE_MODE developer; to nginx.conf file as below:
1 2 3 4 5 6 7 |
server { listen 80; server_name magento2.test.com; set $MAGE_ROOT path/to/magento2; set $MAGE_MODE developer; include other/configurations/file.conf; } |
Now you can see your error that something like that:
Now we have four ways to fix this 500 internal server error in Magento 2.
1, Set permissions for Magento file
Re-update folders/files permission at your end following steps below:
+ Open your terminal and go to your M2 web root folder.
+ Enter the following commands to set permissions:
1 2 3 4 5 6 7 8 9 10 |
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 |
2, Increase php_value memory_limit
Sometimes, you can get “500 internal server error” when you migrate or update your data. Even you can see this error at some specific pages of your Magento site like checkout page, product page… The reason can your server are lacking of resource to run Magento. The solution is Increase php_value memory_limit.
To increase PHP memory limit setting, you can do this value via .htaccess file or php.ini file. Magento itself tries to enforce a default 768M limit across-the-board.
Firstly, please open your php.ini file, add/change the following line:
1 |
memory_limit = 756M |
Secondly, please open your .htaccess file, add the following lines:
1 2 3 |
<IfModule mod_php5.c> php_value memory_limit 756M </IfModule> |
3, Check .htaccess entries file
There are three .htaccess files in your source code. You can find them here:
When you try to install a component such as themes, plugins, patches… or migrate data in Magento, you can get wrong settings in .htaccess file. It can block the installation of new components. Some error in .htaccess can create problems such as: syntax errors, URL rewrite errors, typo errors, etc..
With this case, you need to call your support Engineers to check whether .htaccess file that create problems by temporary renaming that file.
3, Enable Maintenance mode
When you implement your new updates, maintenance mode enabled on Magento. Permission in index.php file is changed by Maintenance flag to 666 which makes it unable to execute by web browsers.
After that, Magento can not change permissions of index.php file or remove the maintenance.flag. You can see “500 error” in this case.
Solution this case, you can remove var/.maintenance.flag file or run this command from your ssh:
1 |
php bin/magento maintenance:enable |
Next, change permission for index.php to 755 and clear cache.
That’s our solution for fixing 500 internal server error in Magento 2. Hopefully all of you can perform.
Thanks for reading!