1. The “504 Gateway Timeout”
A 504 error means Nginx is waiting for a response from PHP-FPM, but PHP is taking too long to process the script.
- The Diagnosis: Check the Nginx error log (
/var/log/nginx/error.log). You’ll likely see “upstream timed out.” - The Fix: Increase the timeout limits in both Nginx and PHP.
- In Nginx: Set
fastcgi_read_timeout 300;in your server block. - In PHP-FPM: Set
max_execution_time = 300in yourphp.ini.
- In Nginx: Set
- Root Cause: Usually caused by a heavy plugin, a massive database migration, or a slow third-party API call.
2. “Error Establishing a Database Connection”
This is the most common hosting error, and it’s almost always related to server resources or credentials.
- The Diagnosis: Check if the MySQL/MariaDB service is actually running:
sudo systemctl status mysql. - The Fix:
- Check Memory: If the service is down, it’s often because the Linux OOM (Out of Memory) Killer terminated MySQL to save the OS. You likely need to add a Swap File or upgrade your RAM.
- Verify
wp-config.php: Ensure theDB_HOSTis set tolocalhostor127.0.0.1. - Repair Tables: Add
define('WP_ALLOW_REPAIR', true);to your config and visityour-site.com/wp-admin/maint/repair.php.
3. File Permissions & “Failed to Write to Disk”
If you can’t upload images or update plugins, your server’s ownership chain is broken.
- The Diagnosis: WordPress usually runs under the
www-datauser on Ubuntu. If your files are owned byroot, WordPress cannot touch them. - The Fix: Reset ownership and permissions via SSH:Bash
sudo chown -R www-data:www-data /var/www/html find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \;
4. PHP Memory Exhaustion
“Allowed memory size of X bytes exhausted.” This happens when a single PHP process tries to use more RAM than the server allows.
- The Fix: Don’t just increase it in
wp-config.php. You must also increase it in yourphp.inifile:memory_limit = 256M(or 512M for heavy WooCommerce sites). - The Catch: If you increase this too high on a small VPS, you risk crashing the entire server under high traffic.
5. SSL Handshake / Mixed Content Errors
After installing an SSL certificate, the site may look “broken” or show security warnings.
- The Fix:
- Database Update: Use WP-CLI to search and replace all
http://instances withhttps://. - Nginx Redirect: Ensure your server block has a proper 301 redirect from port 80 to 443.
- HSTS: Enable the Strict-Transport-Security header to force browsers to use the secure connection.
- Database Update: Use WP-CLI to search and replace all