By default, PHP sets a memory limit to prevent inefficient scripts from using up all available server resources. While this helps maintain server stability, it can also cause problems for modern websites and CMS platforms like WordPress, Joomla, or custom-built applications that require more memory to run smoothly.

If you’ve encountered errors such as “Allowed memory size exhausted”, it likely means your site needs a higher memory limit.

What Is PHP memory_limit and Why Change It?

PHP is the programming language behind most modern websites. It has a memory usage limit — memory_limit — which controls how much server memory a single script can use.

If your site slows down or shows an error like:

Allowed memory size of 134217728 bytes exhausted

it means the current memory limit is too low and needs to be increased.

How to Check the Current Limit

  1. Open any text editor (e.g., Notepad or VS Code)
  2. Paste the following code:
    <?php phpinfo(); ?>
  3. Save the file as phpinfo.php
  4. Upload it to the root directory of your website (via hosting panel or FTP)
  5. Go to https://yourdomain.com/phpinfo.php
  6. Look for memory_limit — that shows your current value (e.g., 128M)

How to Increase the PHP Memory Limit

 Method 1: Using php.ini (if available)

This file stores PHP configuration settings. It’s available on VPS or dedicated servers, or if your hosting provider allows custom PHP configuration.

Steps:

  1. Locate or create the php.ini file
  2. Add this line:
    memory_limit = 512M
  3. Save the file
  4.  Method 2: Using .htaccess (for Apache servers)

If you’re on shared hosting with Apache, look for a file called .htaccess in your site’s root folder. Add this line:

php_value memory_limit 256M

 If this causes a 500 error, your server may be running in CGI mode. In that case, remove the line and try another method.

Method 3: Using wp-config.php (for WordPress)

If you’re running WordPress:

  1. Access your site’s root directory
  2. Open the wp-config.php file
  3. Add this line near the top (before /* That’s all, stop editing! */):
    define('WP_MEMORY_LIMIT', '256M');
  4. Save and close the file

What to Do if It Doesn’t Work

  • Clear your website and browser cache
  • Double-check that you edited the correct file
  • Review PHP error logs from your hosting panel

Conclusion

Even without technical experience, you can increase your PHP memory limit to fix errors and make your site more stable — especially if you use WordPress or another CMS. Just follow the steps above, choose the method that fits your setup, and test the results. If anything goes wrong, you can always revert the changes or contact support.