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

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

hehe…dude. i explained everything above. i’ll reiterate myself a final time.

are you passing PHP_MEMORY_LIMIT anywhere in the command you ran above?

sudo -u www-data php ./occ upgrade

because as far as i can see…you’re not.

if you do:

sudo -u www-data PHP_MEMORY_LIMIT=512M php ./occ upgrade

it should work, like so:

root@nextcloud-754899b6f9-6zs8c:/var/www/html# sudo -u www-data PHP_MEMORY_LIMIT=512M php ./occ upgrade
Nextcloud is already latest version

g’luck :wave:

1 Like

dude, thanks a lot, everything is good witj the last command :
sudo -u www-data PHP_MEMORY_LIMIT=512M php ./occ upgrade
Very good job man

1 Like

Thanks for your help, it worked!

This is what fixed it for me, the -d memory_limit=-1

me@server:/var/www/nextcloud$ sudo -u www-data php -d memory_limit=512M ./cron.php

or actually what I was initially after …

me@server:/var/www/nextcloud$ sudo -u www-data php -d memory_limit=-1 ./occ db:add-missing-indices

A very frustrating experience. Now to deal with the “A background job is pending that checks for user imported SSL certificates” problem

1 Like

Hei Hei,

i have the same issues and even after switching to redis i can not run anny occ command and the cron.php is also not working.

My NextCloud instance is runnig plain with apache and php7.4. No Docker or Nginx involved.