Running a WordPress site or other PHP programs, you may encounter a problem like “Fatal Error: Allowed memory size of xxx bytes exhausted”, which means PHP scripts consume too much of memory, beyond the maximum memory value of your system settings. Many people are anxious when met this error, but don’t worry. Today we are going to introduce 4 useful methods to help you increase PHP memory limit with ease.
Check for PHP Memory Limit
In order to fix the error, you should first check whether a specific program is allocated too much memory. If you make sure all programs have no issues, you can check for your PHP memory limit.
At first, you need to create a new php file, like view-php-info.php, and then copy and paste the below code into it.
<?php phpinfo(); ?>
Upload the file to your hosting server and call it in the browser. Then, you can see the information about your PHP environment configurations, where you will see a series of PHP parameter settings and a special section about memory_limit, like the following screenshot:
How to Increase PHP Memory Limit?
Once clear the memory_limit value, you need to increase it to meet the actual requirements. However, how much memory_limit should be set? This question depends on the needs of your site and applications. For example, the basic PHP memory_limit requirement of WordPress is 32 MB while the recommended setting is 64 MB. If you still want to install some plugins, especially those for image processing, you may increase it to 128 MB or higher.
In the below content, we introduce 4 easy methods to help you complete the process.
- Modify PHP.ini File
- Configure wp-config.php
- Change .htaccess File
- Contact Your Hosting Company
It’s the easiest way to increase PHP memory limit by modifying php.ini file. However, you may don’t have the ability to access to the PHP.ini file on many shared hosting server. under this condition, you can create a new PHP.ini file in the site directories to override the default values.
At first, create a new php file and name it as php.ini. Then, add the below command line into it to increase the memory limit to 128 MB. Alternatively, you can change the value as 64 MB or 256 MB as you need.
memory_limit = 128M
At last, upload this file to your directory where the WordPress site is installed.
If you don’t want to create a duplicate php.ini file, you can increase PHP memory limit by configuring wp-config.php file. Find your this file under the root directory, and then add the follow code into it. As well, you can also change the 128M as 64M or 256M as you want.
Before to start, please note that this method is valid only if php execute as an Apache module. Look for .htaccess file under the root directory. If you don’t find, you can create a new .htaccess file and paste the below code into it.
php_value memory_limit 128M ;
If all the 3 methods cannot solve this problem, you can try to contact your hosting provider. Some shared web hosts usually limit the maximum memory limit or completely forbid you to change it. In this case, you can contact the web host for an efficient solution. If the environment still cannot meet your requirement, you may consider transferring your site to a truly reliable web host.
The following companies are three of the best WordPress hosting companies. They provide superior hosting service along with affordable price, rich features, 99.9% uptime, excellent speed, and professional support. Besides, they also provide reliable VPS hosting plans for customers whose websites have gone out of the shared resources.