Please help me, an idiot, fix my config for the dreaded allowed-memory error

Hello,

I have been getting the dreaded error below for quite a while.

Allowed memory size of 536870912 bytes exhausted (tried to allocate 347852816 bytes) at /var/www/nextcloud/apps/dav/lib/CardDAV/CardDavBackend.php#972

I have read many threads on potential solutions here, but have yet to make the slightest progress toward a solution. This is because I am a Linux idiot with zero expertise, yes, but it is also because there is (I guess?) no simple settings access through NC admin, nor no step-by-step guide for learners to how to edit config directly?

It seems strange that such a simple problemā€“namely, that more memory should be allocated to run NC correctly the next time it startsā€“has no straightforward solution through the admin interface? Or am I missing something? Please help me write this n00b how-to!

Of course, the obvious problem here is that I am unqualified as a Linux user or a NC CLI user. This is my failing, but also seems quite a high barrier to non-nerd adoption.

1 Like

Please post your Nextcloud version.
You can find it with

https://cloud.server.tld/status.php

or in config/config.php

'version' => '...',

This is funny because I canā€™t even find it! :slight_smile:

Iā€™m on the latest, 24.0.2

Must be here in your installation (because of your error log):
/var/www/nextcloud/config/config.php

Iā€™m sure this is answered somewhere in the forumā€¦ Howeverā€¦

The ā€œallowed-memoryā€ error is due to the default memory_limit variable that is set in php.ini at a value lower than 512M.

Youā€™ll need to locate the appropriate php.ini configuration file that is being used by your web server. On a typical Linux box that file will be located somewhere in the /etc directory.

Hereā€™s a one-line bash script to find all the php.ini files in your /etc directory. Caveat, YMMVā€¦

files=$(find /etc -iname php.ini);for f in $files;do echo -e "\nphp.ini files found\n";echo "$f";grep -n memory_limit "$f";echo -e "\n"; done

The line number will appear next to the memory_limit value.

  • Find the one that matches your web server.
  • Change the line to 512M.
  • Restart your web server.

Should be good to go.

1 Like

I can only speak to my experience, but Iā€™ve never seen the one-line bash before, which is enough to make a little headway!

so two files found:

/etc/php/7.4/fpm/php.ini
409:memory_limit = 512M

/etc/php/7.4/cli/php.ini
409:memory_limit = -1

Iā€™m not sure these are the right file because I donā€™t know how Iā€™d know that it ā€œmatches [my] web serverā€, but the first number looks like a good candidate.

When I attempt to edit the first one, it tells me no permission. This I have read about in other places, usually someone saying to ā€œbe rootā€ which Iā€™m fairly certain I am, itā€™s my NC admin user. So how to edit it is the next stuck.

The ā€˜fpmā€™ location is typically associated with nginx web server.

Soā€¦ is that accurate? Are you using nginx?

If so, edit the /etc/php/7.4/fpm/php.ini fileā€¦ line number 409ā€¦

  • Change 512M to some higher value. If you have enough physical memory, try 768M or 1024M
  • restart nginx web server

And see if the error goes away.


Yesā€¦ you need to be root.

add sudo to your edit command.

sudo vi /etc/php/7.4/fpm/php.ini

if youā€™re familiar with vi

Good question, I didnā€™t install from scratch (despite my madd skillz), used this, which doesnā€™t seem to mention nginx but the documentation isnā€™t that clear.

Regardless, I followed your instructions, used vim, had to up it three times, to 4GB??? before CardDav would work. Something is very funky there that it takes that much to serve 100 contacts or so plus a calendarā€¦ but now, thanks to you @irongate, itā€™s the kind of funky that works.

As penance, I will add a more thorough step-by-step this evening, and hopefully other equally lost souls will feel less so as I now do. Many thanks.

4GB sounds a bunch too high.

You may want to poke around in your nginx configuration if the NC instance is running on a platform that is also running other services or is Cloud based.

This serverfault thread may be a good place to start if youā€™re interested:

https://serverfault.com/questions/602308/php-fpm-use-a-lot-of-cpu

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.