Common WordPress Hosting Problems and How to Fix Them

Common WordPress Hosting Problems and How to Fix Them

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 = 300 in your php.ini.
  • 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:
    1. 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.
    2. Verify wp-config.php: Ensure the DB_HOST is set to localhost or 127.0.0.1.
    3. Repair Tables: Add define('WP_ALLOW_REPAIR', true); to your config and visit your-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-data user on Ubuntu. If your files are owned by root, WordPress cannot touch them.
  • The Fix: Reset ownership and permissions via SSH:Bashsudo 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 your php.ini file: 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 with https://.
    • 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.

Leave a Reply

Your email address will not be published. Required fields are marked *