I am pretty sure that most of you have met with the error: in the PHP error log files.
So, in PHP running out of memory indicates that your PHP script is not properly written or contain a bug in it. Another possibility is that the script has to process large amounts of data at once. Occasionally well-designed scripts may require more memory than usual. Especially when handling large amounts of data or when trying to read large files into memory.
Fortunately increasing the memory limit in PHP is a simple task and there are several ways of doing it. Today I am going to show you how you can increase the memory limit in PHP via htaccess, apache, and even inside the PHP script itself.
Setting the PHP memory limit inside the PHP script
For that, you have to add the following line inside your PHP script that requires an increase in memory. So the script will be able to handle large amounts of data.
// note that memory_limit is case sensitive!
// rest of your code follows
Setting php memory limit in .htaccess
As I mentioned previously, this method is also a straightforward one. You just have to add a line into your .htaccess file. But please keep in mind that this change can affect any PHP files within that folder and subfolders. And restarting apache is not required when updating the .htaccess. Just be careful with typing as any typos in the .htaccess file may affect the correct loading of the website.
php_value memory_limit 64M
Setting PHP memory limit in php.ini config file
By editing the php.ini file, you can set the memory limit within the PHP itself. The php.ini file is located under Debian. And then find the line given below and change the number as you like. As this will affect all PHP scripts running under your server, be careful with the number.
Note: To complete the process you have to restart apache.
memory_limit = 64M
Setting the PHP memory limit in APACHE
First, you have to find the virtual host that needs to increase in memory limit in apache. Then add the below line which is in italics.
Note: You have to restart apache to complete the process.
# apache settings for virtual host
php_value memory_limit 64M
# other settings etc. follow as usual.
I hope these methods will work for you. Have a nice day!
Connect with us
We would like to hear about your problems, questions, and suggestions. So feel free to contact us. This is free of charge service that we offer. But we receive thousands of emails per day. So it is impossible to reply to all of them. So we create a Community to help you individually. Go to Community and open help Topic under the relevant category. Please spread this post to your friends by sharing Facebook and other major social media. And make sure to like us on Facebook.