Troubleshooting & Common Errors

How to Fix "Allowed Memory Size Exhausted" PHP Errors and Change memory_limit

By the Domain India teamPublished 13 min read
Knowledge base article
Contents (12 sections)

"Fatal error: Allowed memory size of 134217728 bytes exhausted" is one of the most common PHP errors, and one of the most misunderstood. It means one PHP script asked for more memory than PHP allows a single script to use. This guide explains what that limit is, how to check and raise it on Domain India's cPanel, DirectAdmin and Webuzo hosting, and how to find the real cause when raising it doesn't help.

Key takeaways

Check the limit your site really gets with a one-line ini_get('memory_limit') file or WordPress Site Health. On cPanel, try the MultiPHP INI Editor in the Software section; on any panel, a .user.ini file with memory_limit = 256M is the fallback, and support can change it if neither works. Never put php_value in .htaccess: on our servers it causes a 500 error. 256M is enough for almost every WordPress site; if the error continues at 256M or 512M, a plugin, theme or script is the problem, and your plan's RAM is the ceiling for the whole account anyway.

1. What the error means

A typical message looks like this:

text
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /home/user/public_html/wp-includes/class-wpdb.php on line 2349

memory_limit is a PHP setting that caps how much memory one PHP request may use. It stops one broken script from taking all the memory on the account. The first number is the limit in bytes. The "tried to allocate" number is only the last small request that didn't fit; it is not how much more memory the script needs.

To read the limit, convert bytes to megabytes:

Bytes in the errormemory_limit it means
3355443232M
6710886464M
134217728128M
268435456256M
536870912512M

A related message, Out of memory (allocated 123456789) (tried to allocate 65536 bytes), is different. It usually means the process hit a memory cap outside PHP, such as your account's CloudLinux limit (see section 6), not memory_limit.

2. Check your current PHP settings first

Before you change anything, confirm which limit is actually in force.

  • WordPress: go to Tools → Site Health → Info. The Server section shows the PHP memory limit, upload size and maximum execution time, and the WordPress Constants section shows WP_MEMORY_LIMIT.
  • Any PHP site: create a file with a hard-to-guess name, such as check-7f3a9.php, in the folder where your site runs:
php
<?php
echo 'memory_limit: ', ini_get('memory_limit'), "\n";
echo 'PHP version: ', PHP_VERSION;

Open it in your browser. It prints the value your site really gets, after every panel setting and .user.ini file has been applied. On cPanel, a cache in front of the web server can show an old response for a while, so add ?t=1 (any value) to the address when you check again after a change.

Browser window at a hard-to-guess check file showing one line, memory_limit: 256M and the PHP version, with notes on the ?t= cache trick and deleting the file
What the ini_get check file shows
Don't use a phpinfo() page, and delete the check file

phpinfo() is disabled on our cPanel servers, so a phpinfo page shows nothing useful there, and on any server it publishes paths and settings that attackers scan for. The ini_get file above shows only the values you asked for. Delete it as soon as you're done.

3. Change memory_limit in your control panel

The control panel is the safest method, because it writes the setting in the format your server's PHP handler understands. Menu names can differ between panel versions, and whether memory_limit can be changed from the panel depends on how the server is set up, so if the option isn't there, use section 4 or ask support.

cPanel

  1. Open the MultiPHP INI Editor.
    Sign in to cPanel (see how to log in to cPanel) and open MultiPHP INI Editor in the Software section.
  2. Choose your domain.
    In Basic Mode, select the domain or folder your site runs from.
  3. Set memory_limit
    , for example to 256M, if the editor offers it, and click Apply.
  4. Reload and test.
    Reload the page that showed the error, and confirm the new value with Site Health or your ini_get file.
cPanel MultiPHP INI Editor with Basic Mode and Editor Mode tabs and a drop-down to select the home directory or a domain
MultiPHP INI Editor: choose Basic Mode, then select your domain.

If memory_limit isn't listed or won't change, use a .user.ini file (section 4), or open a ticket with the domain and the value you need.

DirectAdmin and Webuzo

The PHP settings screens on our DirectAdmin and Webuzo servers haven't been checked for this guide, so we don't name a menu here. If you can't find a PHP settings option in your panel, use a .user.ini file or ask support to set the value for you. For choosing the PHP version itself, see how to change your PHP version.

4. .user.ini, php.ini or .htaccess: which one works?

Older guides, including an earlier version of this one, told you to drop a php.ini file into your folder and restart Apache. On shared hosting you can't restart the web server, and our servers run PHP through PHP-FPM or CGI, not as an Apache module. That decides which files work:

MethodWhere it goesOn Domain India shared hosting
Control panel (cPanel MultiPHP INI Editor)Set in the panelFirst choice where the setting is offered; the panel writes the right file for you
.user.iniYour site's folder, e.g. public_htmlWorks with PHP-FPM and CGI; applies to that folder and its subfolders
php.ini in your folderYour site's folderNot reliable; use .user.ini instead
.htaccess php_valueYour site's folderNever: the whole site returns a 500 error
ini_set() in codeInside the PHP scriptCan raise memory_limit for that one script, unless the server has locked the value

A .user.ini file needs just one line per setting:

ini
memory_limit = 256M

Create it with the File Manager in the folder your site runs from. A .user.ini change can take up to 5 minutes to be picked up, because PHP caches these files.

Never put php_value or php_flag in .htaccess

Because PHP doesn't run as an Apache module on our shared servers, Apache doesn't recognise php_value or php_flag lines and the whole site returns a 500 Internal Server Error. If you see one after editing .htaccess, remove the line and set the value in .user.ini or your control panel instead. Our 500 Internal Server Error guide covers the other causes.

If a setting won't change, look for a leftover php.ini or .user.ini in the site's folder or a parent folder, and check that you changed it for the PHP version your site actually uses.

5. WordPress: WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT

WordPress has its own two memory settings in wp-config.php:

  • WP_MEMORY_LIMIT: the memory WordPress asks for on normal pages. The default is 40M (64M on multisite).
  • WP_MAX_MEMORY_LIMIT: the memory WordPress asks for in the admin area and for heavy jobs such as image resizing. The default is 256M.

Add them above the line that says /* That's all, stop editing! */:

php
define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );

WordPress uses these values to raise PHP's limit while it runs, but it can't go above a limit the server has locked, and your plan's memory ceiling still applies. If Site Health shows a lower limit than you defined, raise memory_limit in the control panel or .user.ini too. See our WordPress guide for more.

6. Your plan's memory is the real ceiling

memory_limit applies per request. All the PHP processes on your account share one memory allowance, which CloudLinux enforces. Domain India's plan specifications list the RAM for each plan:

Plan levelcPanelDirectAdminWebuzo
Starter1 GB1 GB1 GB
Growth (Webuzo: Developer)2 GB2 GB2 GB
Business (Webuzo: Agency)3 GB3 GB3 GB

So a memory_limit of 256M on a 1 GB plan leaves room for only a few heavy requests at the same moment. Setting 1024M or -1 (unlimited) doesn't give you more memory. It only lets one runaway script use up the whole account, so every other visitor gets an error. When the account hits its limit, you typically see "Resource Limit Is Reached", a 500, 503 or 508 error, or an Out of memory message, rather than the Allowed memory size error.

You can see whether you are hitting the account limit in your panel's resource usage page: see how to check hosting resource usage and understanding hosting resource limits.

A sensible range

128M suits a simple PHP site, and 256M covers almost every WordPress and WooCommerce site. Go to 512M only for a known heavy job, such as a large import. If you need more than that for normal page views, look for the cause (section 7) before you raise anything.

7. Find the real cause: a plugin, a loop or a big job

If the error continues at 256M or 512M, raising the limit further only delays it. Common causes:

  • A plugin or theme. One badly written plugin can load thousands of database rows into memory at once.
  • An endless loop or recursion. A function that calls itself, or a redirect or hook that keeps firing, eats memory until it hits any limit you set. If the error appears at 128M, 256M and 512M alike, suspect this.
  • A heavy one-off job. Resizing a very large photo or importing a big CSV can legitimately need more memory. Resize images before uploading, and split imports into batches.

To pin it down:

  1. Read the full error.
    The file path in the message often names the plugin or theme, for example wp-content/plugins/plugin-name/. Check the error_log file in your site folder or your panel's error log for repeated entries; see reviewing error logs in cPanel and DirectAdmin.
  2. Turn on WordPress debug logging.
    Set WP_DEBUG and WP_DEBUG_LOG to true to write errors to wp-content/debug.log; see how to enable debugging in WordPress. Turn it off again when you're done.
  3. Disable plugins one by one.
    If you can't reach the dashboard, rename wp-content/plugins to plugins-off in File Manager, check whether the site loads, then rename it back and disable plugins one at a time. Switch to a default theme to rule out the theme.
  4. Update or replace the culprit.
    Update it, check its support forum, or replace it with a lighter alternative.

8. Other PHP settings you'll often change

The same panel screens and .user.ini file hold the settings behind other common errors:

SettingWhat it controlsTypical valueError you see when it's too low
upload_max_filesizeLargest single file PHP accepts64M"The uploaded file exceeds the upload_max_filesize directive"
post_max_sizeLargest whole form or upload request64M or more, never less than upload_max_filesizeUpload silently fails or the form arrives empty
max_execution_timeSeconds a script may run60 to 300"Maximum execution time of 30 seconds exceeded"
max_input_varsNumber of form fields PHP reads3000 to 5000Menus or theme options don't save completely

A very long max_execution_time doesn't help a script stuck in a loop. For uploads, see PHP upload file size limit. Settings are kept per PHP version, so after you change your PHP version, check them again.

9. Where Domain India hosting fits

Domain India's cPanel and DirectAdmin plans run on CloudLinux, which gives each account its own memory allowance; on Webuzo, PHP scripts get 64 MB of memory by default. See the hosting compatible technologies list for what else runs on each product.

If your site is well configured and your resource usage page still shows you regularly reaching the memory limit, a bigger plan gives your account more RAM. Growth plans double the Starter allowance to 2 GB:

cPanel Growth
₹200/mo + GST
  • 50 GB NVMe SSD Storage
  • 100 GB Monthly Bandwidth
  • 5 Websites
  • 50 Email Accounts
See plan details
DA Growth
₹150/mo + GST
  • 30 GB NVMe SSD Storage
  • Unmetered Bandwidth
  • 5 Websites
  • 50 Email Accounts
See plan details

The cards show current list prices; 18% GST is added at checkout. If you need more memory than shared hosting offers, or full control over PHP settings, a VPS lets you set any value you want. For anything the panel won't let you change, open a support ticket and tell us the setting, the value and the site. Support is on 24/7 live chat, and tickets get a first response within 15 minutes.

10. Frequently asked questions

What does "Allowed memory size of 134217728 bytes exhausted" mean?

A PHP script tried to use more than the 128 MB that PHP's memory_limit allows one request. Raise memory_limit to 256M. If the error continues at 256M or 512M, a plugin, theme or script is using too much memory and needs fixing.

How do I increase the PHP memory limit on cPanel?

Open MultiPHP INI Editor in the Software section of cPanel, choose Basic Mode, select your domain, set memory_limit if it is offered and click Apply. If it isn't offered, put the line memory_limit = 256M in a .user.ini file in your site's folder, or ask support to change it.

Should I use php.ini, .user.ini or .htaccess?

Use your control panel first. If you need a file, use .user.ini, which works with the PHP-FPM and CGI handlers on Domain India shared hosting. Don't use php_value in .htaccess: on our servers it makes the whole site return a 500 error.

How do I check the memory limit my site is really using?

In WordPress, open Tools, Site Health, Info and look under Server. On any PHP site, upload a file containing <?php echo ini_get('memory_limit'); open it in your browser, then delete it. phpinfo() is disabled on our cPanel servers, so don't rely on a phpinfo page.

What memory_limit should I set for WordPress?

256M covers almost every WordPress and WooCommerce site. You can also set WP_MEMORY_LIMIT to 256M and WP_MAX_MEMORY_LIMIT to 512M in wp-config.php, but WordPress can't go above a limit the server has locked or the memory your plan provides.

Can I set memory_limit to -1 or a very high value?

You shouldn't. On shared hosting all your PHP processes share your plan's memory, so an unlimited or very high value lets one faulty script use it all and break the site for other visitors. It doesn't add memory to your plan.

I raised memory_limit but the error still shows the old value. Why?

Another file is probably overriding it, such as an old php.ini or .user.ini in your site folder or a parent folder, or you changed the setting for a different PHP version than the one your site uses. Check the value with an ini_get file, and allow up to 5 minutes for .user.ini changes to apply.

Ready for more room to grow? Compare cPanel, DirectAdmin and Webuzo hosting plans, or see our VPS plans if you need full control over PHP.

Still seeing memory errors?

Send us the full error message, the page where it appears and the memory limit you have set. Our team will help you find the cause.

Open a support ticket

Ready when you are

Get DirectAdmin hosting from ₹100/mo + GST

See plans

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app