Many online bloggers recommend using self-hosted WordPress platform for building websites. However, WordPress will throw many fatal errors that need analysis to resolve. On other hand, there are error messages that you can easily understand like “Fatal Error – Allowed memory size of —— bytes exhausted“. The most probable cause for this error could be the PHP memory limit. In this article, we will explain how to increase PHP memory limit to fix this error. Also, learn how to increase PHP max execution time in WordPress.
PHP Memory Limit
PHP is the server side scripting language and backbone of your WordPress site. Core WordPress software, themes and plugins will contain different types of PHP files. These PHP script files need certain level of memory for completing the task. In order to protect the hosting servers, many hosting companies set the maximum allowed limit for your hosting account. This is essential especially when you are hosted on shared hosting server.
Most memory related errors occur when the PHP memory limit set by your hosting company is not sufficient to run all WordPress processes. For example, the consumption of PHP memory will be more when you have lot of plugins installed. The problem can also happen when you try to install newer version of WordPress or update your theme. In order to resolve the problem, the first step is to check your current PHP memory limit. After finding the maximum limit allowed on your server, you can use one of the explained methods to increase the current PHP memory limit.
How to Check PHP Memory Limit in WordPress?
The simple way to check your current PHP memory limit is to create a dummy PHP file in your WordPress installation directory. In order to do that you need to login to your hosting account and use “File Manager” app. Alternatively, you can use FTP client to create a PHP file. Here we explain with the File Manager app cPanel hosting like HostGator or Bluehost. You can follow the same process in custom hosting panels like SiteGround Site Tools.
- Go to your hosting account and click on “Advanced” section to navigate to cPanel section.
- Find “File Manager” app available under “File” section and open it.
- Locate your WordPress installation directory; by default it will be “public_html” unless you changed it during installation. You need to look for subdirectory folder incase if you have WordPress installed on subdomain.
- Click on a “File” and create dummy PHP file with a name “php-memory.php”.
- You can name the file as you want but ensure to add .php as an extension.
- Now select the created file and click on “Edit” link to add the following code and save your changes.
<?php phpinfo() ;?>
Open the PHP file in a browser window by adding your domain name before the file name. For example: www.your-site-name.com/php-memory.php. Look for the parameter “memory_limit” which will show your current PHP memory limit set by the host.
Make sure to delete the dummy PHP file after you found the memory limit.
How to Increase PHP Memory Limit in WordPress?
The PHP memory limit is decided by the host and check out with your host before you modify it yourself with any unacceptable value. For example, if your host set the limit as 32M and increasing the value to 128M will result in your account being deactivated by the host. Before this happens, have a discussion with the hosting company and they should be able to set appropriate value for you.
Read on further if you want to check and increase the memory limit on your own:
1. Modifying wp-config.php file
Open “wp-config.php” file located in your WordPress installation directory and add the following line.
Here we have mentioned the memory limit of 64M which you can change to 128M or any other allowed values by your host.
2. Modifying .htaccess File
Add the below line in your .htaccess file. If your WordPress installation does not have “.htaccess” file, you may need to create one.
php_value memory_limit 64M
3. Modifying php.ini File
Most of the hosting companies do not allow modifying php.ini file and the file will not exist in your installation directory. If your host allows, create a php.ini file and add the following line:
memory_limit = 64M
Some companies like Bluehost offers an app in hosting account to modify the parameters. When you are in the hosting account, find and open “MultiPHP INI Editor” app.
On the next screen, choose your domain’s document root as a location under “Editor Mode”.
Add the above code and save your changes. Alternatively, you can toggle “Basic Mode” and scroll down to find “memory_limit” PHP directive. Here, you can view the current value and change as per your need. Don’t forget to scroll down to the end and click “Apply” button to save your changes.
If you are not sure what to do with memory exhausted error it is highly recommended to contact your host. This may help you to avoid messing things yourself especially if the issue is not resolved after modifying “wp-config.php” or “.htaccess” files. Also, remember to do only one method either modifying “.htccess” or “wp-config.php” or “php.ini”. Do not try to modify all files at a time to avoid undesirable results.