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

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

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.

2 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:

1 Like

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

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

root@3:/var/www/html# sudo -u www-data PHP_MEMORY_LIMIT=512M php -f cron.php
root@3:/var/www/html# sudo -u www-data php ./occ
Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 438272 bytes)

yah, you didn’t pass the env var for the 2nd command, sudo -u www-data php ./occ…but you can see it worked for the 1st command:

sudo -u www-data PHP_MEMORY_LIMIT=512M php -f cron.php

enjoy
:slight_smile:

root@f9df223e7483:/var/www/html# sudo -u www-data php ./occ upgrade
Fatal error: Allowed memory size of 2097152 bytes exhausted

the same error