Home / Articles / WordPress / How to Fix PHP Memory Limit Issues in WordPress

How to Fix PHP Memory Limit Issues in WordPress

WordPress is arguably the best content management system for bloggers, entrepreneurs, and small business owners with no technical background whatsoever. With the help of plugins, themes, and a user-friendly dashboard, anyone can build the site of their dreams without ever touching code.

But as users begin pushing out of their comfort zone and exploring the true capabilities of WordPress, they may encounter various errors that may lock them out of their dashboard.

If you’re like me who constantly fiddle around the components of the platforms I use, then you’ll encounter the dreaded “white screen of death” — at least once during your time with WordPress.

A common occurrence would be the fatal PHP memory exhausted error, which can be triggered by something as simple as installing a new plugin. The cause of it, however, is when a certain component of your WordPress site uses up more memory than your PHP allows.

This is more likely to occur on websites that push their resource allocation with fancy visuals, rich content, and plugins. One example is an e-commerce site, which consumes a ton of data and memory to operate.

Fortunately, increasing the memory limit is a straightforward solution that can fix most, if not all, PHP memory exhausted errors. Here’s how to do it:

Logging in to Your Hosting Account

First of all, there are multiple ways to access your hosting account’s cPanel. Some companies need you to log in to an official portal, while others only require you to add “/cpanel” in your website’s URL.

Once you arrive at your hosting account’s cPanel login page, go ahead and provide your credentials.

Your cPanel credentials are sent to you via email by your hosting provider during the initial setup process. If you lose this, you can contact their customer service for assistance.

Upon logging in, you should see a screen with sections for your web server’s files, domains, software and so on. Look for the ‘File Manager’ icon to proceed.

Most modern cPanel platforms have two general areas in the file manager: a folder browser and the main explorer area.  If your hosting account has multiple websites, you should be able to find their respective folders in the folder browser to the left. Look for the website that has the PHP memory limit issue to view its contents.

In the root folder of your WordPress site, look for a file called ‘wp-config.php.' This is where you can manually increase the size of your PHP memory limit.

Take note that — depending on your hosting company — there are different ways to edit files in your cPanel.

In this particular example, you can either select ‘Code Edit’ from the right-click menu or select the file and click ‘Code Editor from the main toolbar.
This should bring up the code editor on a new tab. To start with the fix, create a new line right underneath the ‘<?php’ tag, which should be at the very top of the code.

Tip: The first thing you may notice upon getting the PHP memory exhausted fatal error is the file path along with the corresponding line number mentioned the error message. Following this in your file manager is a waste of time since it doesn’t trace where the error originates.

To modify the PHP memory limit, you just need to paste a short line of code:

define( 'WP_MEMORY_LIMIT', '256M' );

‘M’ stands for megabytes. That said, the code above instructs WordPress to raise the PHP memory limit to 256 MB, which should be more than enough to ensure the normal operation of most websites — even for online stores.

Newly-added codes should be highlighted in blue. After adding the code to your wp-config.php file, click the save button. That’s it, go ahead and refresh your WordPress site to see if the PHP memory issue is resolved.

Disabling Plugins

If the above solution didn’t fix your problem, the next thing you can try is to deactivate plugins and reactivate them one at a time. Without access to your WordPress dashboard, you can complete this step through the file by following the instructions below.

First, navigate back to your WordPress website via the file manager and navigate to ‘wp-content’ and look for the ‘plugins’ folder.

Your goal here is to make this directory inaccessible to your WordPress installation. To do this, simply rename the plugins folder to anything you want. For the sake of this guide, let’s call the new folder ‘plugins.old.'

If a plugin causes your PHP memory exhaustion issue, then you should be able to log in to your WordPress dashboard again.

Go over to ‘Plugins’ > ‘Installed Plugins’ to see this page.

Now, head back to your file manager and revert the ‘plugins.old’ folder name into ‘plugins’.

Refresh your WordPress dashboard to re-scan all the system folders. If you followed all the steps above correctly, then you should have all your plugins back — only this time they will be deactivated.

To figure out which plugin causes the problem, reactivate all the plugins one by one until your dashboard stops working again. Don’t worry; you can easily regain access by repeating the renaming process. Once you do, however, don’t reactivate the problematic plugin and contact its publisher for a possible fix.

Reverting to the Default Theme

Lastly, if you suspect that the PHP memory exhaustion error is caused by a new theme, then you can resolve it by reverting to the default theme.

You can do this by navigating to ‘wp-content’ > ‘themes’ in your cPanel’s file manager and deleting the currently active theme’s folder. Just remember to create a backup by downloading it before doing so.

Take note that renaming the folder wouldn’t work because WordPress will still detect the theme files. But if you delete the theme’s folder, WordPress will be forced to revert to the default theme. You’ll know if the process worked if you can log in to your dashboard again.

As a WordPress user, troubleshooting is one of the crucial skills you need to learn to survive and grow.

Here is another useful post that can help you fix some issues with this content management system. Good luck and have fun learning!


Photo of author

Article by Christopher Jan Benitez

Keep Reading