On this page
- Where should you look first when the site breaks?
- How do you turn on WordPress debug logging safely?
- How do you fix the white screen or a 500 error?
- What causes "Error establishing a database connection"?
- How do you fix "Allowed memory size exhausted"?
- How do you repair file permissions?
- How do you stop a redirect loop?
- What else breaks often, and how do you check it?
- Questions
Where should you look first when the site breaks?
Read the logs before changing anything; they usually name the file and line that failed. Three places cover almost every case on a LEMP server:
sudo tail -n 50 /var/log/nginx/error.log
sudo journalctl -u php8.3-fpm --since "30 min ago" --no-pager # Ubuntu 24.04
sudo journalctl -u php-fpm --since "30 min ago" --no-pager # Rocky, Alma
sudo journalctl -u mariadb --since "30 min ago" --no-pagerAlso check the basics that break every application at once: disk space with df -h, memory with free -h and service state with systemctl --failed. A full root disk stops MariaDB from writing and makes PHP sessions fail, which often shows up as a confusing mix of symptoms. Use the usage monitoring tutorial to spot growth before it becomes an outage.
How do you turn on WordPress debug logging safely?
Write errors to a log file instead of the screen, so visitors never see paths or queries. WP-CLI can edit wp-config.php without opening an editor:
cd /var/www/example.net
sudo -u www-data wp config set WP_DEBUG true --raw
sudo -u www-data wp config set WP_DEBUG_LOG true --raw
sudo -u www-data wp config set WP_DEBUG_DISPLAY false --raw
sudo tail -f wp-content/debug.logReload the failing page and watch the log. Lines starting with PHP Fatal error point to the plugin or theme folder that crashed. Switch all three values back to false when you finish, and delete debug.log, because it can grow quickly and may contain sensitive details.
How do you fix the white screen or a 500 error?
A blank page or HTTP 500 almost always means PHP hit a fatal error. If the debug log blames a plugin, disable it from the shell; you do not need the dashboard.
sudo -u www-data wp plugin list --skip-plugins --skip-themes
sudo -u www-data wp plugin deactivate broken-plugin --skip-plugins
# no clue yet? switch everything off, then enable one by one
sudo -u www-data wp plugin deactivate --all --skip-plugins
sudo -u www-data wp plugin activate seo-pluginIf the theme is the cause, move to a default theme with wp theme install twentytwentyfive --activate --skip-themes. Two other common 500 sources: a PHP extension missing after a distribution upgrade (compare php -m with what the error asks for) and an FPM pool that reached pm.max_children, which logs a clear warning in the FPM journal. Also run sudo -u www-data wp core verify-checksums to catch core files that were changed or half-written by an interrupted update.
What causes "Error establishing a database connection"?
Either MariaDB is down or the credentials in wp-config.php no longer match. Test each in turn:
systemctl status mariadb --no-pager
sudo -u www-data wp config get DB_NAME
sudo -u www-data wp config get DB_USER
mariadb -u wpuser -p -e "SELECT 1;" wpsite
sudo -u www-data wp db checkIf the service stopped, the MariaDB journal usually says why: no disk space, a crashed table or the kernel killing it for memory. Check for the last one with sudo journalctl -k | grep -i "out of memory". On small plans, a swap file and lower innodb_buffer_pool_size keep MariaDB alive; the swap file guide shows the steps. If the login test fails, reset the password inside MariaDB with ALTER USER 'wpuser'@'localhost' IDENTIFIED BY 'new-password'; and update DB_PASSWORD to match.
How do you fix "Allowed memory size exhausted"?
Raise the WordPress limit and the PHP limit together, because WordPress cannot go above what PHP allows.
sudo -u www-data wp config set WP_MEMORY_LIMIT 256M
sudo -u www-data wp config set WP_MAX_MEMORY_LIMIT 512M
php --ini | grep Loaded
grep -n memory_limit /etc/php/8.3/fpm/php.ini
sudo sed -i 's/^memory_limit = .*/memory_limit = 512M/' /etc/php/8.3/fpm/php.ini
sudo systemctl restart php8.3-fpmOn Rocky and Alma edit /etc/php.ini and restart php-fpm. Note that the CLI and FPM read different ini files on Debian and Ubuntu, so changing one does not change the other. If a single page needs more than 512 MB, treat that as a sign of a faulty plugin rather than a reason to keep raising the number.
How do you repair file permissions?
WordPress files should belong to the PHP-FPM user, with directories at 755 and files at 644. Wrong ownership causes failed updates, FTP prompts and upload errors.
cd /var/www/example.net
sudo chown -R www-data:www-data .
sudo find . -type d -exec chmod 755 {} +
sudo find . -type f -exec chmod 644 {} +
sudo chmod 640 wp-config.phpUse nginx:nginx on Rocky and Alma, and restore the SELinux label for uploads with sudo restorecon -Rv /var/www/example.net followed by the httpd_sys_rw_content_t context on wp-content. The file permissions guide explains the numbers if they are new to you.
How do you stop a redirect loop?
Loops usually come from the site address settings disagreeing with how visitors arrive, for example http in the settings while Nginx forces https. Check and correct both values:
sudo -u www-data wp option get home
sudo -u www-data wp option get siteurl
sudo -u www-data wp option update home 'https://example.net'
sudo -u www-data wp option update siteurl 'https://example.net'
curl -sIL http://example.net | grep -iE '^(HTTP|location)'If the server sits behind a TLS-terminating proxy, WordPress sees plain HTTP and keeps redirecting. Add this near the top of wp-config.php, above the line that loads wp-settings.php:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}Clear any page cache afterwards, otherwise the browser may keep the old redirect. The HTTPS and www redirect guide shows a clean single-hop setup.
What else breaks often, and how do you check it?
- Stuck maintenance mode: an interrupted update leaves a
.maintenancefile in the web root. Delete it and rerun the update. - 404 on every page except the home page: the Nginx
try_filesline is missing; it must end in/index.php?$args. - 413 Request Entity Too Large: raise
client_max_body_sizein Nginx andupload_max_filesizein PHP. - Scheduled posts never publish: WP-Cron needs visits. Run it from system cron instead with
*/5 * * * * cd /var/www/example.net && wp cron event run --due-nowin the www-data crontab. - Locked out of the admin: reset the password with
wp user update siteadmin --prompt=user_pass.
When a fault keeps coming back, restore last night's copy and compare. Our optional daily backups add-on and your own off-server copies both help here.
Questions about Fix common WordPress errors
Is it safe to run WP-CLI as root?
It works with --allow-root, but files it creates end up owned by root and WordPress then cannot update them. Run it as the PHP-FPM user with sudo -u www-data (or nginx) instead.
Why do I see 502 Bad Gateway instead of 500?
Nginx could not reach PHP-FPM at all. Check that the FPM service is running and that the socket path in fastcgi_pass matches the one in /run/php/ or /run/php-fpm/.
How do I find which plugin slows a page down?
Disable plugins one at a time with WP-CLI and time the page with curl -o /dev/null -s -w "%{time_total}\n" https://example.net/. A large drop after one deactivation names the culprit.
Can a full disk really cause a database error?
Yes. MariaDB stops accepting writes when the disk is full, and WordPress reports that as a connection error. Free space, then restart the database.
What should I do if the site was hacked?
Take it offline, verify core with wp core verify-checksums and plugins with wp plugin verify-checksums --all, change every password and key, and restore from a clean backup taken before the break-in.
More in Websites, CMS and shops
- WordPress on Nginx, PHP-FPM, MariaDB
- Back up WordPress (3-2-1 rule)
- WordPress caching with Redis
- WooCommerce shop setup
- Ghost publishing platform
- Moodle learning platform
- phpBB forum
- Flarum forum
- Discourse community forum
- MediaWiki on Nginx and MariaDB
- Magento Open Source with OpenSearch
- PrestaShop store on Nginx
- OpenCart shop on Nginx
- Matomo web analytics
- Static site with Nginx and rsync
- Joomla on Nginx and PHP-FPM
- Drupal with Composer and Drush
- Vanilla Forums open source