How to allow PHP use more memory

Some of you might have seen this error before

fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 54 bytes)

By default php allows you to have 128MB this should suffice most basic websites. But certain CMS like Magento require more than 128MB to run. so today I’m going to show you.

Find the line that says memory_limit=128M

(Note: M = MB, G = GB)

So its valid to do memory_limit=2G

If you want no limit on your server you can use memory_limit=-1

In Ubuntu with apache2:

cd /etc/php5/apache2/php.ini

In RHEL, Fedora, or CentOS:

cd /etc/php5/php.ini

If you have shared hosting you can either request for the memory limit to but raised if if your ok editing PHP files you can add this to somewhere that gets loaded every time the page is ran.

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