How to Increase PHP Memory Limit for Your Website

PHP’s memory_limit prevents scripts from overloading server resources, but modern websites like WordPress or Joomla often need more memory to avoid errors like “Allowed memory size exhausted.” This guide simplifies checking and increasing the PHP memory limit using AvaHost’s cPanel or other hosting setups, with practical examples and troubleshooting tips.

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

Increasing the PHP memory limit is a simple fix for “memory exhausted” errors, ensuring your WordPress, Joomla, or custom site runs smoothly. With AvaHost’s cPanel tools, you can apply the methods above—php.ini, .htaccess, or wp-config.php—and test changes easily. These steps and examples empower you to optimize performance without technical expertise, keeping your site stable and efficient.