Definitive Solution to the 500 Error and Critical Server Errors in WordPress/cPanel: Diagnosis with Logs and PHP

1. Immediate Diagnosis of the 500 Error

The 500 Internal Server Error is a generic HTTP status code indicating a server failure. To identify the cause:
  • Check the error logs in cPanel: cPanel → Metrics → Errors or via SSH with tail -f /home/user/logs/error_log.
  • Enable WP_DEBUG by adding to wp-config.php: define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true );.
  • Check the PHP log at /usr/local/apache/logs/error_log or via phpinfo().

2. Common Causes and Technical Solutions

2.1 PHP Memory Limits

A PHP Fatal error: Allowed memory size exhausted requires increasing the limit:
  • Edit php.ini: memory_limit = 256M (or higher).
  • Alternative via .htaccess: php_value memory_limit 256M.
  • For WordPress specifically: define('WP_MEMORY_LIMIT', '256M'); in wp-config.php.

2.2 Conflicting Plugins or Themes

Key resource: Official WordPress Conflict Documentation.
  • Access via FTP/SFTP (e.g., FileZilla) and rename the /wp-content/plugins folder to plugins_old.
  • Test with a default theme (Twenty Twenty-One) by renaming /wp-content/themes/tema-activo.

2.3 .htaccess Failures

Temporarily delete the .htaccess file (back it up first) and regenerate it from WordPress at Ajustes → Enlaces permanentes.

3. 503 and 502 Errors: Service Unavailable and Bad Gateway

Related to PHP-FPM or Apache/Nginx:
  • Overloaded MySQL: Check slow queries with phpMyAdmin or enable slow_query_log.
  • Process limits in WHM: Home → Service Configuration → PHP-FPM → Max Children.

4. Advanced Log Analysis

Typical structure of a critical error:
Log ExampleProbable Cause
[proxy_fcgi:error] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Error: Call to undefined functionDeleted PHP function or unloaded extension (e.g., imagick).
mod_security: Access denied with code 500ModSecurity rule blocking requests (requires whitelisting in WHM).

5. PHP Optimization in cPanel

  1. Select a stable version (PHP 8.0+ for WordPress 5.6+) via cPanel → Select PHP Version.
  2. Required extensions: opcache (enable in php.ini), curl, mbstring.
  3. Set max_execution_time to 300 seconds for long operations.

Frequently Asked Questions (FAQs)

How do I restore my site if I can’t access the WordPress panel?

Use FTP/SFTP to disable plugins (by renaming the folder) or restore a backup from cPanel → File Manager → public_html → backups.

Why does my 500 error only occur on specific pages?

This indicates conflicts with custom queries or shortcodes. Check the hooks (actions/filters) in functions.php or custom templates.

How do I interpret server HTTP status codes?

Quick guide: 500 (internal failure), 502 (Bad Gateway), 503 (Service Unavailable), 504 (Timeout). Full documentation at MDN HTTP Status.
Comparte este contenido:

Deja un comentario

🤖 IA

×
Hola. ¿Qué duda o consulta tienes sobre este contenido?