How To Increase PHP Memory Limit

by lifeLinux on May 11, 2011

If you have seen an error like “Fatal Error: PHP Allowed Memory Size Exhausted” in webserver logs or in your browser, this means that PHP has exhausted the maximum memory limit. There are several techniques to increase the PHP memory limit and you only need to use one of them.

Changing memory limit globally from php.ini

To find locate the php.ini file used by your web server. You can use the phpinfo() PHP function to find it. After, type the following command to edit php.ini file:

[root@lifelinux ~]# vi /etc/usr/local/etc/php.ini

Edit the memory_limit parameter in the php.ini file

memory_limit = 32M

You will require root access to make changes to php.ini on the system. This change is global and will be used by all php scripts running on the system. Once you change this value, you will need to restart the web server in order for it to become active.

Changing memory limit using .htaccess

Edit the .htaccess file in the web root directory. Look for the section:

php_value memory_limit 32M

This method will only work if PHP is running as an Apache module.

Changing memory limit inside a single php script

Set this directive inside a single php script:

ini_set('memory_limit', '32M');

Related Posts:

{ 1 comment… read it below or add one }

Emmanuel Chenze March 29, 2012 at 10:25 am

What if i just use all the methods? Is that wrong?

Reply

Previous post:

Next post: