500 Internal Server Error means the website’s own code or configuration failed while building the page. The message is deliberately vague so it does not leak details to visitors; the real reason is written to the error log. Find the log line and the fix is usually obvious.
If you are visiting the site
There is nothing to fix on your side, and clearing your cache will not help. Try again later, or tell the site owner which page failed and roughly when, which helps them find the log entry.
If you run the site
1. Read the error log
This is the single most useful step. Load the failing page, then read the newest lines:
sudo tail -n 50 /var/log/nginx/error.log
sudo tail -n 50 /var/log/apache2/error.log
sudo tail -n 50 /var/log/httpd/error_log
Use the first for Nginx, the second for Apache on Ubuntu and Debian, the third for Apache on AlmaLinux, Rocky and RHEL. PHP-FPM may also keep its own log at /var/log/php8.3-fpm.log or /var/log/php-fpm/www-error.log.
On shared hosting, look for Errors or Logs in the control panel, or a file called error_log in your site’s folder.
2. Match the log line to the cause
| Log says | Cause | Fix |
|---|---|---|
PHP Fatal error: Uncaught Error: Call to undefined function | Code calls something that does not exist, often after an update or with a missing PHP extension | Step 3, or install the extension |
PHP Parse error: syntax error, unexpected | A typo in a PHP file | Undo the last edit to the named file |
Allowed memory size of 134217728 bytes exhausted | The page needs more memory than PHP allows | Step 6 |
Maximum execution time of 30 seconds exceeded | The page ran too long | See 504 Gateway Timeout |
Invalid command 'RewriteEngine' or .htaccess: ... not allowed here | Bad or unsupported .htaccess line | Step 4 |
Permission denied on a file | PHP cannot read the file | Step 5 |
Request exceeded the limit of 10 internal redirects | A rewrite rule sends the request round in a loop | Check rewrite rules in .htaccess or the virtual host |
A PHP fatal error names the file and line:
PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /var/www/example.com/public/wp-content/plugins/some-plugin/includes/helpers.php:42
The path tells you which plugin, theme or file is at fault. Here the fix is installing the missing mbstring PHP extension: sudo apt install php8.3-mbstring on Ubuntu, sudo dnf install php-mbstring on RHEL-based systems, then restart PHP-FPM.
3. Undo the last change
A 500 that started right after an update, a new plugin, a PHP version change or an edit is almost always caused by that change. Roll it back first and investigate afterwards. If you changed PHP versions, check that the extensions you need are installed for the new version too:
php -m
4. Check .htaccess on Apache
A single typo in .htaccess causes an instant 500 on every page. Rename it to test:
mv .htaccess .htaccess-off
If the site loads (perhaps with broken links), the file was the problem. On WordPress, go to Settings > Permalinks and click Save to write a fresh one. Lines starting php_value or php_flag cause a 500 when PHP runs as PHP-FPM rather than as an Apache module; move those settings to php.ini or a .user.ini file instead.
5. Check permissions and ownership
Files should usually be 644 and folders 755, owned by the user PHP runs as. Many servers refuse to run scripts that anyone can write to (777). To reset a site’s permissions:
sudo find /var/www/example.com/public -type d -exec chmod 755 {} \;
sudo find /var/www/example.com/public -type f -exec chmod 644 {} \;
On AlmaLinux, Rocky and RHEL, SELinux can also block access to files copied from elsewhere. sudo restorecon -R /var/www/example.com resets their labels.
6. Raise PHP’s memory limit
Allowed memory size exhausted means the page needs more memory than PHP’s memory_limit allows. Raise it in php.ini or the PHP-FPM pool, then restart PHP-FPM:
memory_limit = 256M
On WordPress you can also set define( 'WP_MEMORY_LIMIT', '256M' ); in wp-config.php, up to the server’s limit. If a page needs much more than 256 MB, something is wrong with it, such as a plugin loading a whole table into memory, and more memory only hides it.
On WordPress
WordPress often hides the error. Turn on logging in wp-config.php, above the line that says That’s all, stop editing:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
Errors now go to wp-content/debug.log without being shown to visitors. Turn it off again when you are done.
To rule out plugins, rename the plugins folder, which switches every plugin off at once:
cd wp-content
mv plugins plugins-off
If the site loads, rename it back and switch plugins off one at a time to find the culprit. With WP-CLI, wp plugin deactivate --all does the same. To rule out the theme, switch to a default theme with wp theme activate twentytwentyfive.
Confirm it is fixed
curl -I https://example.com/the-page/
HTTP/2 200 means it works. Load a few other pages too, especially the admin area and forms, since a broken plugin may only fail on some pages.
Related
- White screen of death, WordPress’s version of a hidden 500.
- 503 Service Unavailable, when the server refuses work instead of failing.
- Error establishing a database connection.
Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.



