[SOLVED] Occ command; PHP Fatal error, Allowed memory size of XXX bytes exhausted

I had the exact same issue.
There is an issue on github there: Allowed memory size of xxx bytes exhausted in current latest-container · Issue #1413 · nextcloud/docker · GitHub
They are mentioning the addition of the -d memory_limit=-1 option to the php command (I suppose setting the limit to an infinite value).
I can confirm that this resolves the issue for me, while waiting for a newer release to fix the issue !

2 Likes

Same issue here, tried with php7.3, php7.4, php.8.0, tried editing memory limit in php.ini & the command line -1, to no avail. occ simply gets killed every time. Thank God I didn’t go through with the browser upgrade, would’ve crashed my install. I just hope this gets fixed in a future release, looking forward to test drive 21.

I limited the memory to 8 GB and it went into ‘OOM’ mode… I don’t think that removing the limit is THE solution as it will just feast on memory. (upadte:) … until the OOM killer sets a stop to it.

1 Like

Mine goobeled up 32GB of RAM, might there be some other mem option in php that needs setting?

1 Like

Similar, after upgrading to version 21, the occ upgrade command got a segmentation fault.
So I manually upgraded, the instance works in the cloud, but the occ command always uses up all RAM and returns with a segmentation fault. Is this a nextcloud error or php?

It looks like a bug. I posted already to this newer topic:

It was reported to the bug tracker.

The segmentation fault is what happens to me when I set memory_limit=-1

I had the same problem. However, as soon as I deactivate APCu as memcache, the memory consumption is back to normal.

3 Likes

I had APCu activated in the nextcloud config.php. It seems I didn’t have apc.enable_cli=1 in /etc/php/8.0/cli/conf.d/20-apcu.ini. After I added that line to the file occ worked and there was no segmentation error anymore.

26 Likes

Switched to redis and it works.

This leads me to the conclusion that either pecl-apcu or nextcloud did something strange. As the -RC didn’t had the problem, I suspect the latter.

2 Likes

Many thanks!
Add the line and the error was gone. :slight_smile:

2 Likes

This solved my issue as well! Thank you. I was using the FreeNAS/TrueNAS provided plugin/jail.

/usr/local/etc/php.ini

[apcu]
apc.enable_cli=1

4 Likes

Where would you find this file in the nextcloud docker?

Edit: The file was /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini, but the line apc.enable_cli=1 was already there. Any help?

having the same issue using the docker tag: 21.0.0-apache

i’ve tried the above suggestions to no avail.

I have nextcloud running with the the official docker image and also have this issue after upgrading.

Apparently the PHP_MEMORY_LIMIT is not in the environment variables of the www-data user which is typically used to execute occ commands. Therefore out of memory.
So what worked is to prepend all occ commands with “PHP_MEMORY_LIMIT=512M”, e.g. in crontab:
/usr/bin/docker exec nextcloud_app_1 su - www-data -s /bin/bash -c ‘PHP_MEMORY_LIMIT=512M php -f /var/www/html/cron.php’"

See for reference:

4 Likes

noice! you da man!

Hello,
I have me too upgraded Nextcloud 21.
Can you help me please, i have same problem Allowed memory…when i execute OCC commands
when i write this command line :
@NAS01:~# docker exec nextcloud_nextcloud_1 su - www-data -s /bin/bash -c ‘php -d memory_limit=-1 -f /var/www/html/cron.php’ ----No error but it no works because i have
always message: Allowed memory…
And so i tried this :
@NAS01:~# docker exec nextcloud_nextcloud_1 su - www-data -s /bin/bash -c ‘PHP_MEMORY_LIMIT=512M php -f /var/www/html/cron.php’
Return : php: $’\342\200\230PHP_MEMORY_LIMIT=512M’: command not found
Please, this command do you set in crontab file ? where is the file ?
Regards,

@fab06 i’m doing this with success:
sudo -u www-data PHP_MEMORY_LIMIT=512M php -f cron.php

1 Like

where are you execute this command ? on your container docker Netxcloud ?
Regards,

correct…this is my whole command, but i’m using this as a CronJob which isn’t relevant to you.

the big thing is making that env var, PHP_MEMORY_LIMIT, available to the www-data user:

kubectl exec -i $(kubectl get pods -o custom-columns=:metadata.name -n nextcloud) -n nextcloud -- sudo -u www-data PHP_MEMORY_LIMIT=512M php -f cron.php