What is PHP Memory Limit? Increase Memory Limit
Last updated: 31 December 2025
What is the PHP Memory Limit?
The PHP memory limit (memory_limit) determines how much RAM a PHP script may use at maximum. This is a security measure that prevents a single script from consuming all available memory and bringing down your entire server. By default, this limit is often set to 128MB, but that can be too little or too much, depending on your application.
When a PHP script tries to use more memory than the configured limit, you get the infamous error message "Fatal error: Allowed memory size exhausted". This means your script was stopped because it needed too much memory. For visitors to your website, this often means a white page or an incomplete page.
How the PHP Memory Limit Works
PHP scripts run on your web server and use RAM memory to process data. Each time someone visits your website, a PHP process starts that needs memory. This memory is used for variables, database results, images being manipulated, and all other operations your script performs.
The memory_limit setting in PHP determines the maximum per script. If you set the limit to 256MB, each individual PHP script may use a maximum of 256MB. Note: this is per script, so if 10 visitors are on your site simultaneously, 10 scripts can run, each using up to 256MB.
You can check the current memory_limit via a simple PHP script. Create a file containing <?php phpinfo(); ?> and view the value at "memory_limit". Many hosting providers also show this information in their control panel.
The limit is set at different levels. The server has a default value in the php.ini configuration. With shared hosting, you can often adjust this via .htaccess or a local php.ini. With managed hosting like WordPress hosting, the limit is usually pre-optimized.
Why a Memory Limit is Important
Without a memory limit, one poorly programmed script could crash your entire server. Imagine a bug in your code creating an infinite loop that keeps loading more data into memory. Without a limit, this script would consume all available RAM until the server crashes.
On shared hosting servers, hundreds of websites share the same resources. If your script uses too much memory, other websites on the same server can be affected. That's why hosting providers enforce strict limits to ensure fair usage.
For your own application, the limit also prevents small problems from having major consequences. A PHP script needing more memory than expected often signals an underlying issue. Perhaps you're loading too much data at once, or a plugin has a memory leak.
Setting the Right Memory Limit
For a basic WordPress website, 128MB to 256MB is usually sufficient. If you use many plugins or a page builder like Elementor, you often need 256MB to 512MB. Webshops with WooCommerce run comfortably on 256MB to 512MB, depending on the number of products and plugins.
If you regularly see the memory exhausted error message, that's a sign to increase the limit. But do this moderately. Don't jump straight to 512MB if 256MB is too little. Increase gradually and monitor whether the problem is resolved.
Some tasks temporarily need more memory. Think of importing large databases, generating PDF files, or processing images. For such specific scripts, you can increase the memory_limit locally with ini_set('memory_limit', '512M'); at the top of your script.
Note that a higher memory limit isn't always the solution. If your script structurally uses too much memory, the problem often lies in the code. Better optimize your queries, load data in smaller chunks, or cache intermediate results.
Adjusting the Memory Limit
With most hosting providers, you can adjust the PHP memory limit yourself. In cPanel, find this under "Select PHP Version" or "MultiPHP INI Editor". In DirectAdmin, look under "PHP Settings". In Plesk, go to "PHP Settings" for your domain.
Via .htaccess, you can adjust the limit by adding this line: php_value memory_limit 256M. This only works if your provider uses mod_php. With PHP-FPM or FastCGI, this method doesn't work.
Another option is creating a local php.ini in your website's root. Put in it: memory_limit = 256M. This works with most modern hosting configurations. Always check via phpinfo() after adjustment whether the new value is active.
For WordPress, you can also modify wp-config.php. Add: define('WP_MEMORY_LIMIT', '256M'); for the frontend and define('WP_MAX_MEMORY_LIMIT', '512M'); for the admin panel. WordPress uses these constants to increase the PHP memory_limit when needed.
Troubleshooting Memory Problems
If you still have memory problems despite a high memory_limit, it's time to debug. Install a plugin like Query Monitor for WordPress to see which queries or functions use the most memory. This helps you identify the culprit.
Check your error logs for patterns. Does the error only occur on certain pages or actions? Then you know where to look. Common causes are: too large database queries, unoptimized images, bad plugins, or too much data loaded into memory at once.
Consider implementing caching with plugins like Redis or Memcached. These caching solutions reduce the memory burden of your PHP scripts by storing and reusing frequently used data in memory.
With persistent problems, upgrading to a VPS or dedicated server may be the solution. Then you have more control over server configuration and more resources available. Check our hosting comparison for suitable options.
Frequently Asked Questions
How much does web hosting cost on average?
Web hosting costs between €3 and €15 per month for shared hosting on average. VPS hosting starts around €10-€20 per month, and dedicated servers from €50 per month.
Can I upgrade to a different package later?
Yes, with most hosting providers you can easily upgrade to a larger package when your website grows. This can usually be done without downtime.
Is Dutch hosting better than foreign hosting?
For Dutch visitors, Dutch hosting is often faster due to the shorter distance. Additionally, communication with support is easier and you comply with GDPR legislation.
Was this article helpful?
Compare hosting packages directly to find the best choice for your situation.
Related articles
Migrate website: complete step-by-step plan
Migrating website to new hosting? Follow this step-by-step plan to migrate your website safely and without downtime.
301 Redirect: Permanent Redirect Explained
Learn what a 301 redirect is, when to use it and how it affects your SEO.
404 Error: Page Not Found Explained
Discover what a 404 error is, what causes it and how to fix and prevent 404 errors.
500 Internal Server Error: Causes and Solutions
Learn what a 500 error is, common causes and how to fix this server error.
503 Service Unavailable: Server Overloaded
Discover what a 503 error means, what causes it and how to fix or prevent it.