How to Fix PHP Memory Limit Errors (Complete Beginner’s Guide)
That Frustrating “Allowed Memory Size Exhausted” Error
Have you ever been happily working on your website — uploading a theme, running a plugin, or executing a script — and suddenly you’re hit with this dreaded message?
Fatal error: Allowed memory size of 134217728 bytes exhausted
If yes, you’re not alone. This cryptic-looking PHP memory limit error has frustrated thousands of developers, bloggers, and website owners.
It appears out of nowhere, breaks your workflow, and sometimes even crashes your site entirely.
But don’t worry — by the end of this guide, you’ll not only understand what causes PHP memory limit errors, but also learn exactly how to fix them using a few easy methods (no deep coding required!).
Let’s dive in and fix this once and for all.
Why PHP Memory Limit Errors Happen
To put it simply, your website ran out of memory.
PHP (the programming language most websites run on) uses a specific amount of memory to execute tasks — things like loading plugins, themes, or generating pages. When your script tries to use more memory than it’s allowed, PHP throws this error and stops processing.
Here’s a quick analogy
Think of PHP memory like a fuel tank.
If your car (website) tries to drive farther than the fuel (memory) allows, it’ll stall — until you add more fuel or reduce how much it consumes.
Common Causes of PHP Memory Limit Errors:
- Too many plugins or heavy plugins
- Large images or files being processed
- Poorly coded themes or scripts
- Insufficient memory allocation in php.ini
- Server resource limits set by your hosting provider
Why Fixing It Matters
Ignoring this error isn’t an option — it can:
- Make your website load slower or even crash completely.
- Prevent you from installing or updating plugins/themes.
- Affect user experience and SEO rankings (Google hates broken pages).
- Lead to lost conversions if your visitors can’t access content.
A small fix today can save you from a major headache later.
Let’s go through all the proven methods to fix PHP memory limit errors safely and effectively.
Step-by-Step: How to Fix PHP Memory Limit Errors
We’ll cover five reliable methods, from easiest to most technical.
You don’t need to try them all — start from the top and stop once the error disappears.
Step 1: Increase PHP Memory Limit in wp-config.php (for WordPress Sites)
If you’re using WordPress, this is the simplest and most common fix.
What to Do:
- Open your website files via File Manager (in cPanel) or FTP.
- Find the file named
wp-config.phpin the root directory. - Open it and scroll down until you see this line:
/* That's all, stop editing! Happy blogging. */ - Just add this line above it:
define( 'WP_MEMORY_LIMIT', '256M' ); - Save changes and refresh your site.
Pro Tip:
If the error persists, try increasing it further to 512M, but avoid going too high — it may hit your server’s actual physical limits.
Step 2: Modify php.ini File
The php.ini file is PHP’s main configuration file — it tells PHP how much memory it can use.
What to Do:
- Locate your php.ini file (usually in your hosting root or
public_html). - Open it and find this line:
memory_limit = 128M - Change it to:
memory_limit = 256M - Save and restart your web server (or ask your hosting provider to do it).
Note:
If you can’t find php.ini, you can create one manually:
memory_limit = 256M
Upload it to your site’s root folder — this works for most shared hosting setups.
Step 3: Use .htaccess File (Apache Servers)
If you’re on an Apache server, you can increase memory using your .htaccess file.
What to Do:
- Open your site’s root directory and locate the
.htaccessfile. - Add this line:
php_value memory_limit 256M - Save the file and refresh your site.
If the server throws an Internal Server Error (500), remove this line immediately — it means your host doesn’t allow PHP changes through .htaccess.
Step 4: Change PHP Memory Limit via cPanel
If you’re not comfortable editing files manually, you can use your hosting control panel (like cPanel or Plesk).
What to Do:
- Log into your hosting dashboard.
- Find the section called “Select PHP Version” or “PHP Settings.”
- Look for memory_limit — you’ll see something like 128M.
- Change it to 256M or higher (depending on your site’s needs).
- Save and apply changes.
This method is beginner-friendly and doesn’t require coding access.
Step 5: Contact Your Hosting Provider
If none of the above methods work, it’s likely that your host has capped the maximum PHP memory limit.
Simply contact their support team and ask:
“Hi, could you please increase my PHP memory limit to 512M?”
Most hosting companies (like Hostinger, Bluehost, or SiteGround) will do it instantly — especially if you’re on a premium or business plan.
Comparison Table: Memory Limit Options
| Method | Difficulty | Works On | Recommended For |
|---|---|---|---|
| wp-config.php edit | ⭐ Easy | WordPress | Bloggers & site owners |
| php.ini edit | ⭐⭐ Medium | All sites | Developers |
| .htaccess update | ⭐⭐ Medium | Apache servers | Tech-savvy users |
| cPanel setting | ⭐ Easy | Shared hosting | Beginners |
| Contacting host | ⭐ Very Easy | All types | Everyone |
Pro Tips to Prevent PHP Memory Limit Errors
Let’s make sure this doesn’t happen again.
1. Use Lightweight Themes and Plugins
Avoid bloated themes and plugins that eat up resources. Use only what’s essential.
Tip: Test plugin impact using tools like Query Monitor.
2. Optimize Your Media
Compress large images using free tools like TinyPNG or ShortPixel.
Big image files can consume unnecessary memory during processing.
3. Clean Up Your Database
Old post revisions, spam comments, and transients slow down PHP.
Use plugins like WP-Optimize or manually clean up through phpMyAdmin.
4. Upgrade PHP Version
Newer PHP versions (like 8.1 or 8.2) are faster and more memory-efficient.
You can change this from your hosting control panel.
5. Use Caching
Install caching plugins to reduce how often PHP processes data.
Examples: WP Rocket, LiteSpeed Cache, or W3 Total Cache.
Expert Insights
From years of experience managing client websites, one thing is clear — most PHP memory limit errors aren’t from low hosting limits, but from inefficient code or overloaded sites.
In other words, increasing memory is just the bandage.
The cure is website optimization — trimming unnecessary plugins, cleaning databases, and updating PHP regularly.
Here’s what I recommend:
- Audit your site monthly.
- Check memory usage with your host’s resource monitor.
- If you frequently hit limits, consider upgrading to VPS or cloud hosting.
You May Also Like : Fix PHP Not Running on Localhost: 2025 Guide
Frequently Asked Questions (FAQs)
1. What is the default PHP memory limit?
Most hosting providers set it between 64M and 128M by default.
2. What’s a safe value to increase it to?
Usually 256M is enough for most WordPress or PHP sites.
If your site uses heavy plugins or eCommerce systems, go for 512M.
3. Will increasing PHP memory make my website faster?
Not directly — but it will prevent crashes and improve stability during heavy processes.
4. Can I change memory limit on shared hosting?
Yes, but only within the host’s allowed range. If you can’t change it via file edits, contact support.
5. What if my site still breaks after increasing memory?
Then the issue might be plugin conflicts or coding bugs — try disabling plugins one by one or check error logs.
Conclusion: Take Control of Your Website’s Power
PHP memory limit errors may seem intimidating at first, but they’re one of the easiest problems to fix once you understand them.
Now you know:
- Why the error happens
- How to fix it (multiple ways!)
- How to prevent it from returning
So the next time your screen flashes that scary “Allowed memory size exhausted” message — you’ll know exactly what to do.
Try these methods today and bring your site back to life!
You can also read:
How to Fix WordPress Plugin Conflicts
#PHPErrors #WebsiteOptimization #WebDevelopment #WordPressTips #FixErrors
4 Responses