How do I fix a Magento 2 500 Internal Server Error after a deploy?
After a deploy, a Magento 2 500 error almost always means one release step left the store broken. The fix is to read the logged exception, then rerun only the deploy step it points to. Six things usually break: file ownership, generated code, the database schema version, static content, a new module, or OPcache. The steps below apply to self-hosted Magento Open Source and Adobe Commerce 2.4.x
Quick answer
For a Magento 2 500 error after a deploy, check var/log/exception.log, the newest var/report/ file and the PHP-FPM error log. Reset ownership on var/, generated/, pub/static/ and app/etc/ to the web server user. Depending on the log, run setup:upgrade with setup:di:compile, or setup:static-content:deploy, then restart PHP-FPM and flush the cache. Each command fixes a different cause, so let the log decide which you need.
What to check before fixing a Magento 2 500 error on a live store
- Back up the database before setup:upgrade, since schema changes and data patches are hard to undo.
- Run every bin/magento command as the file owner, never as root. Root-owned files in generated/ or var/ stop Magento writing there, which alone can break every request.
- Never fix permissions with chmod -R 777. It leaves the codebase writable by anyone who gains a foothold on the server.
- Don’t switch production to developer mode just to see the error. Visitors would see full stack traces. Read the logs or reproduce the error on staging instead.
- If your deploy tool keeps the previous release, rolling back is faster than debugging under live traffic.
How to fix a Magento 2 500 error after a deploy
1. Find the real Magento 2 500 error in the logs
The 500 page hides the actual exception. Magento records it in one of three places:
- var/log/exception.log and system.log hold the exceptions Magento caught itself.
- var/report/, where each file name matches the report ID on Magento’s “There has been an error processing your request” page.
- The PHP-FPM, Nginx or Apache error log. Fatal errors that stop Magento loading land here, like memory exhaustion or a missing PHP extension.
tail -n 50 var/log/exception.log
ls -t var/report | head -1
If the Magento logs are empty, the failure sits in the server layer. Check .htaccess, the Nginx config and PHP-FPM itself.
2. Fix file ownership and permissions
Deploy commands run as root create files the web server can’t write to. Magento then fails on every request. Reset ownership to your web server user. Replace www-data with the user your server actually uses.
chown -R www-data:www-data var generated pub/static pub/media app/etc
find var generated pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated pub/static pub/media app/etc -type d -exec chmod g+ws {} +
3. Run setup:upgrade and setup:di:compile
Two log messages mean you need setup:upgrade and setup:di:compile. “Please upgrade your database” means a module’s schema version is ahead of the database. Adobe’s database upgrade guide requires setup:upgrade after any module install or update. “Class does not exist” or Interceptor errors mean generated/ still holds classes from the previous release.
Run setup:upgrade first because, per Adobe’s extension management guide, it clears generated classes and asks you to run setup:di:compile. If the release changed composer.lock, run composer install before anything else so vendor/ matches.
bin/magento maintenance:enable
composer install --no-dev
bin/magento setup:upgrade
bin/magento setup:di:compile
If setup:di:compile fails, its output names the broken class or module. That is the real bug in the release, and no cache flush will fix it.
4. Redeploy static content
Production mode doesn’t generate CSS and JavaScript on request. A static deploy that stopped partway leaves pub/static incomplete. Pages then load unstyled, or fail outright. Deploy every locale your store views use.
bin/magento setup:static-content:deploy en_US nl_NL
5. Reset OPcache and flush every cache layer
Production servers often set opcache.validate_timestamps to 0. PHP then never rechecks files on disk and keeps running the old release until PHP-FPM restarts. Restart PHP-FPM first. Running bin/magento cache:flush then clears the Redis cache backend and purges the Varnish hosts set in env.php’s http_cache_hosts.
sudo systemctl restart php8.3-fpm # use your PHP version, e.g. php8.2-fpm
bin/magento cache:flush
bin/magento maintenance:disable
Common causes of a Magento 2 500 error after deploy
Match your log message to a row below to trace the Magento 2 500 error to its cause.
| What the log says | Likely cause | Fix |
|---|---|---|
| Permission denied, or failed to open stream in var/ or generated/ | Files created by root during the deploy | Reset ownership of var/, generated/ and pub/static/ to the web server user |
| Class does not exist, or Interceptor errors | Stale generated code | Run setup:upgrade, then setup:di:compile |
| Please upgrade your database | setup:upgrade skipped or failed | Run setup:upgrade, then setup:di:compile |
| The exception names a third-party vendor namespace | A module added or updated in this release | bin/magento module:disable Vendor_Module, then setup:upgrade and setup:di:compile |
| Allowed memory size exhausted | PHP memory_limit too low for the request or compile | Raise memory_limit for both PHP-FPM and CLI |
| Call to undefined function | A PHP extension missing on the server but present in the build environment | Install the extension and align PHP versions |
| Parse error in app/etc/env.php | Config file edited or overwritten during the deploy | Restore env.php from backup |
| Nothing in Magento logs, but the web server log shows an error such as Invalid command ‘<IfVersion’ | A missing Apache module, or an .htaccess, Nginx or PHP-FPM fault | Load the missing module or fix the server config |
How to prevent a Magento 2 500 error on the next deploy
A Magento 2 500 error that follows every release usually signals a deploy process problem rather than a code problem. Moving setup:di:compile and static content deploy into a CI build step means the server only receives finished code. Pair that with deploys that run as the file owner and keep the previous release one symlink away. If the 500s keep coming back, our Magento development team can audit how you build and ship releases.
Related Answers
Still need help?
Talk to our Magento experts
Still seeing a 500 after checking the logs and rebuilding? We can trace the exception and fix the deploy step that caused it.