Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Fatal Error: Allowed Memory Size - Helpful Tip


Go to End


5 Posts   8202 Views

Avatar
ckd

Community Member, 18 Posts

27 March 2011 at 12:16am

Edited: 27/03/2011 12:19am

Hi,

I experienced this error after a recent install of SilverStripe and thought I would post some tips here in case others experience the same issue:

From my experience, this error occurs when the PHP memory on your server is too low. Quite often, even after you change the memory limit, this message can still persist. In my case, after seeing the SilverStripe warning, on install, that my memory was too low, I contacted my hosting provider who increased the limit to 128M from 32M. Once they made these changes, I found that a php.ini file was now in the root directory containing the following:

memory_limit = 128M

I reinstalled SilverStripe, (no warnings this time), and all was well until I added my first module, in this case DataObjectManager. Everything looked ok on the front end of the site, after doing a dev build and flush, however when I went back to the admin I received a blank page with the dreaded "Fatal error: Allowed memory size of 33554432 bytes exhausted..."

So I was a bit perplexed as to why, after increasing the memory size, that I was receiving this error message.

When you see this error, look at the number ie amount of bytes, in my case '33554432' and divide by 1024 then divide again by 1024 = 32. So, even though you have increased the limit to say 128M, you can still see that SS is recognising only 32M of available memory.

Next step is to check that you have indeed increased the memory limit. Grab you text editor and add the following code:

<?php
   phpinfo();
?>
then save the file as phpinfo.php

Upload this file to the root directory of your server and open the page ie

www.mysite.com/phpinfo.php

You should now be able to view your php settings. Scroll down until you find 'memory_limit' and check to see if it is correct and that it has been indeed been increased to the desired amount. You will probably find that it has been.

Now, create a folder in your root directory ie 'temp' and re upload phpinfo.php to that folder and then open in your browser ie

www.mysite.com/temp/phpinfo.php

Checking the memory_limit setting, you may see here that it still reflects 32M. From this we can deduce that having increased the memory limit with your hosting provider, it only has affected the root directory of the site and not all directories.

To change this, open your htaccess file and add the following:

SetEnv PHPRC "/home/mysite/public_html/"

The path is the location to your php.ini file. Now open the phpinfo.php file from the temp folder again, refresh your browser, you should now see that the memory limit has been increased. Hence, memory limit across all folders should now be at the desired amount ie 128M.

I put my php.ini file within the cgi-bin and changed the path in htaccess to reflect this. You also want to the following in your htaccess file:

<Files php.ini>
order allow,deny
deny from all
</Files>

This worked for me and hopefully may help others experiencing the same issue, however, may not work for everyone.

Avatar
Mindfusion

Community Member, 7 Posts

10 June 2012 at 11:39pm

Thank you very much ckd , this was a life saver

Avatar
figj

Community Member, 12 Posts

15 January 2013 at 1:49pm

Thanks for the excellent explanation about modifying the ".htaccess" to order for a top level "php.ini" to work...

Previously I'd been placing my "php.ini" in my "framework" (sapphire) directory and keep having to remember to put it back after each upgrade!

Avatar
Bigfork

Community Member, 23 Posts

16 January 2013 at 12:25am

On CPanel hosting I use a similar method, may be of use if SetEnv doesn't work:

suPHP_ConfigPath /PATH/TO/php.ini

e.g.

suPHP_ConfigPath /wwwdata/username/public_html/php.ini

Avatar
DesignerX.com.au

Community Member, 107 Posts

16 January 2013 at 2:41am

Edited: 16/01/2013 2:43am

Another way which solved this problem for me on 2 different hosting provider (CrazyDOmain.com.au & another one, cant remember it ) .
Add a php.ini with the new memory limit in the framework/ folder ! yes , after hours of test this worked .
BTW, I only have problems on hosting provided by clients, my VPS with HostGator works perfect .

Edit: @figja , I just read your post . I can imagine how much trail & error it took to solve it :)