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

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

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

dude…you’re not passing the env var.

sudo -u www-data php ./occ upgrade
^ do you see PHP_MEMORY_LIMIT=512M anywhere in there?

sudo -u www-data PHP_MEMORY_LIMIT=512M php ./occ upgrade
^ try this and it’ll work.

On my container Netxcloud :
Container details

PHP_MEMORY_LIMIT= -1
PHP_UPLOAD_LIMIT= -1
NEXTCLOUD_VERSION = 21.0.0

sure, you can pass PHP_MEMORY_LIMIT=-1 too and it’ll work. the issue you’re having is that you’re not passing that as the www-data user.

the issue with the docker image is that PHP_MEMORY_LIMIT isn’t available to the www-data user’s env. what you showed above is probably available to the root user, but not to www-data.

my previous response of passing the env var of PHP_MEMORY_LIMIT each time when you run a command will solve your problems.

i do this :

  1. root@NAS01:/# docker exec -it nextcloud_nextcloud_1 bash
    root@f9df223e7483:/var/www/html# su - www-data -s /bin/bash -c ‘php -d memory_limit=-1 -f /var/www/html/cron.php’
  2. root@f9df223e7483:/var/www/html# sudo -u www-data php ./occ upgrade
    Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 438272 bytes)
    It doesnt work