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:
it means the current memory limit is too low and needs to be increased.
How to Check the Current Limit
- Open any text editor (e.g., Notepad or VS Code)
- Paste the following code:
phpinfo(); - Save the file as phpinfo.php
- Upload it to the root directory of your website (via hosting panel or FTP)
- Go to https://yourdomain.com/phpinfo.php
- 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:
- Locate or create the php.ini file
- Add this line:
memory_limit = 512M - Save the file
- 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:
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:
- Access your site’s root directory
- Open the wp-config.php file
- Add this line near the top (before /* That’s all, stop editing! */):
define('WP_MEMORY_LIMIT', '256M'); - 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.


