Overview
The following explains how to increase the PHP memory limit of a website.
Background
Every installation of PHP is configured with a default memory limit. This works well for most websites, however, if your website requires more memory, you may receive the following error indicating that the memory limit has been reached:
Fatal error: Allowed memory size of 94371840 bytes exhausted (tried to allocate 5072 bytes)
You can then increase it by editing your user's php.ini (phprc).
Different types of memory
There are different types of memory you should be aware of before updating your PHP memory limit. For example:
- Server Memory (RAM) — This is the amount of memory the physical server uses. On a shared server, this value is shared between all customers. On a VPS or Dedicated server, this value is isolated to that specific machine.
- User PHP memory — The amount of PHP memory a user has for all its websites. If a user has three websites, all combined would use this value.
- WordPress PHP memory — The amount of memory available for WordPress to use. This is related to PHP memory but is configured within the website's wp-config.php file.
Make sure you are adjusting the correct values to ensure your issue is resolved.
How to increase the PHP memory limit
The following sections explain how to manage the PHP memory limit for your site.
Increasing the User PHP memory limit
-
You must create/edit your user's phprc file to increase this limit. See the following articles for instructions on how to create a phprc file:
If the file already exists, view the following articles for instructions on how to update it:
Add the following line to increase it to 300MB:
memory_limit = 300M
If you find you're increasing the memory a large amount, it's time to consider moving off of Shared Hosting, as your website has greater needs than this plan can reliably provide.
Increasing the WordPress PHP memory limit
-
If you're running a WordPress site, the setting in your phprc file may not take effect since WordPress is overriding it in your wp-config.php file. To fix this, just update your wp-config.php file with the specific memory limit. For example:
- Log in to your WordPress site via FTP or SSH.
- Make sure you're in your site's directory. You'll see your wp-config.php file here.
- Edit this file (using FTP or SSH) to add the following lines. Make sure to add these before the wp-settings.php inclusion. For example:
define( 'WP_MEMORY_LIMIT', '300M' ); define( 'WP_MAX_MEMORY_LIMIT', '300M' ); /** Sets up WordPress vars and included files. */ require_once(ABSPATH . 'wp-settings.php');
See this article for further information.
Killing off all running php processes
Make sure to kill running php processes to ensure your new settings take effect.
Confirming your changes
After you've edited the file and killed off all PHP processes, you should check to confirm the values have updated. You can do this by creating a phpinfo.php file. If you do not see your changes have updated, try killing off your PHP processes again.