Skip to content

How to fix WordPress HTTP ERROR 500 and Memory Issue

I was about to write a new blog post after a long time, but suddenly encountered an HTTP ERROR 500! I thought I’d document the process of how I resolved it.

Can’t Access the Site? 500 ERROR

First, when I tried to access my site, I was greeted with the following message:

Your connection is not private. Attackers might be trying to steal your information from 54.180.73.135 (for example, passwords, messages, or credit cards). Learn more

Initially, I thought it was an HTTPS issue, but since the SSL certificate was still valid for a good while, I figured it had to be something else. So I tried accessing the WordPress admin page, but got an HTTP ERROR 500.

To investigate further, I connected to the server via Amazon Lightsail’s SSH. You can connect by clicking that icon in the image.

Then, I checked the Apache error logs using the following command:

sudo tail -n 100 /opt/bitnami/apache2/logs/error_log

I found the following error message in the logs:

[Fri Sep 27 14:56:26.762708 2024] [proxy_fcgi:error] [pid 3558472:tid 140217285551872] [client 101.47.157.220:48674] AH01071: Got error 'PHP message: PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 7260068256 bytes) in /opt/bitnami/wordpress/wp-admin/includes/class-wp-filesystem-direct.php on line 39', referer: https://lucy-the-marketer.kr/kol/growth/local-regression-overview

Reading this, it meant that a PHP memory limit was exceeded—trying to allocate about 7.2GB of memory when the allowed limit was 512MB. This indicated that some plugin or theme was caught in an infinite loop or causing abnormal processes.

Checking the Plugins

First, I tried deactivating the plugins by renaming the plugins directory. This way, WordPress wouldn’t recognize the installed plugins.

sudo mv /opt/bitnami/wordpress/wp-content/plugins /opt/bitnami/wordpress/wp-content/plugins_disabled

After that, I accessed the site again, and it loaded successfully. Now, I needed to find out which plugin was causing the problem.

First, I restored the plugins directory to its original name.

sudo mv /opt/bitnami/wordpress/wp-content/plugins_disabled /opt/bitnami/wordpress/wp-content/plugins

Then, I navigated to the plugins directory and listed the installed plugins.

cd /opt/bitnami/wordpress/wp-content/plugins
ls

Running the ls command displays all folder names in the directory. Now, I moved all plugins to a temporary directory and activated them one by one to see which one caused the issue.

sudo mkdir ../plugins_temp
sudo mv * ../plugins_temp/

Then, I moved each plugin back individually:

sudo mv ../plugins_temp/plugin_name .

After restoring each plugin, I checked the site to see if any issues arose. Eventually, I found that when I moved W3 Total Cache back, the site became inaccessible again.

Removing the Problematic Plugin

Since I still couldn’t remove the plugin via the admin page, I decided to delete it through SSH. I removed the plugin and deleted cache files and folders.

sudo rm -rf /opt/bitnami/wordpress/wp-content/plugins/w3-total-cache
sudo rm -rf /opt/bitnami/wordpress/wp-content/cache/
sudo rm -rf /opt/bitnami/wordpress/wp-content/w3tc-config/
sudo rm -f /opt/bitnami/wordpress/wp-content/advanced-cache.php
sudo rm -f /opt/bitnami/wordpress/wp-content/db.php
sudo rm -f /opt/bitnami/wordpress/wp-content/object-cache.php

Now, to apply the changes, I restarted the Apache server:

sudo /opt/bitnami/ctlscript.sh restart apache

Deactivating the plugins reset some settings, which was a bit of a hassle, but I’m glad the issue was resolved. WordPress is great, but occasionally it forces me to practice my terminal skills… 😢

Leave a Reply

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