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.

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