If you’ve ever worked with WordPress, you may have encountered the dreaded PHP Memory Limit Error. Don’t worry—you’re not alone, and it’s usually a pretty easy fix! In this article, we’ll break down what this error is, why it happens, and how you can fix it in just a few simple steps.
What Is the PHP Memory Limit Error?
The PHP Memory Limit Error occurs when your WordPress website runs out of available memory to execute the scripts it needs. In simple terms, your website is trying to use more memory than your server is allowing.
PHP is the programming language behind WordPress, and like any other application, it needs memory (RAM) to function. Your hosting server allocates a specific amount of memory to each website, and if your website needs more than what’s been allocated, you’ll hit the PHP memory limit.
You can read about the server requirements that Divi requires in the article we wrote about Divi hosting requirements.
Why Does This Error Occur?
The PHP memory limit can be exceeded for several reasons:
- Heavy Plugins or Themes: Some WordPress themes and plugins (especially page builders like Divi) can be resource-heavy, requiring more memory than what your server allocates by default.
- High Traffic: If your website experiences a sudden surge in traffic, it may require more memory to handle the increased load.
- Poor Hosting Configuration: If you’re using a shared hosting plan, the PHP memory limit is often set very low to accommodate many websites on a single server.
- Too Many Scripts: If you’re running multiple plugins or custom scripts, each of them uses PHP memory. Too many running at the same time can push you over the limit.
How Does the PHP Memory Limit Error Present Itself?
When the PHP memory limit is exceeded, WordPress will often display an error message similar to this:
Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) in /home/your-site/public_html/wp-includes/plugin.php on line 1234
Alternatively, your website might just crash or display a white screen of death, which is a blank page with no content. This indicates that WordPress ran out of memory before it could load any content.
How to Fix the PHP Memory Limit Error
Thankfully, fixing the PHP Memory Limit Error is straightforward and can be done in a few easy steps. Here’s what you need to do:
Step 1: Edit Your wp-config.php File
1. Access Your Website via FTP or File Manager
- You’ll need to log into your hosting control panel (such as cPanel) or use an FTP client like FileZilla to access your site files.
- Navigate to the root directory of your WordPress installation, where you’ll find a file called wp-config.php.
2. Open wp-config.php for Editing
- Right-click on the file and select “Edit” or open it with a text editor.
3. Add the Following Code to Increase the Memory Limit
- Insert the following line of code right above the line that says /* That’s all, stop editing! Happy blogging. */:
define('WP_MEMORY_LIMIT', '256M');
This code increases your PHP memory limit to 256M (megabytes), which is typically more than enough for most WordPress sites. If you continue to face issues, you can try increasing it to 512M, but in most cases, 256M should resolve the problem.
4. Save the Changes
- Once you’ve added the code, save the file and upload it back to your server (if using an FTP client).
Step 2: Check Your PHP Settings via php.ini (Optional)
If editing the wp-config.php file doesn’t work or you want to make a more permanent change, you can also adjust the memory limit in your server’s php.ini file.
1 . Locate the php.ini File
- Some hosting providers allow access to this file via the control panel. If you can find it, search for a line that reads:
memory_limit = 128M
2. Increase the Memory Limit
- Change this value to 256M, or a higher number if necessary:
memory_limit = 256M
3. Save the Changes
- After editing, save the file and restart your server (this can often be done via your hosting control panel).
Step 3: Consider a Good Hosting Company
While increasing the memory limit can fix this issue in the short term, it may be a sign that your current hosting provider isn’t giving you the resources you need to run your website efficiently. If you find yourself running into memory issues regularly, it’s worth considering switching to a hosting provider that offers more robust resources.
One great option is Cloudways, which offers scalable cloud hosting specifically optimized for WordPress websites. With Cloudways, you can adjust your server resources easily, ensuring that your site always has the memory it needs to run smoothly—even under heavy load.
Why Cloudways?
- Managed Cloud Hosting: Focus on building your site, while Cloudways handles the server management.
- Scalability: Adjust server resources as your site grows, ensuring you always have enough memory and processing power.
- Free Trial: Cloudways offers a 3-day free trial, so you can test the platform without commitment. If memory issues are a common occurrence for you, Cloudways could be the perfect solution.
Fix the PHP Memory Limit Error in Minutes
Running into a PHP Memory Limit Error can be frustrating, but with a few simple tweaks to your wp-config.php file, you can get your site back up and running in no time. If you frequently experience memory issues, upgrading to a more powerful hosting provider can help you avoid these headaches in the future.
Remember, Cloudways is designed for websites that need flexibility and power, and you can try it out for free with their 3-day trial—perfect for seeing how it handles your WordPress and Divi sites.
Hope this helped!