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

@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.

Thanks, it was really helpful

Thanks ! I don’t have good memories of the web updater on a big installation, thanks to you I managed to use occ.

Thank u sooo much!
It helped me to run occ again.

Thanks. This saved me after my upgrade from 20.0.8 to 21.0.1

After the upgrade any command I executed or the scheduled cron job Nextcloud runs was consuming all memory and swap on the server. i couldn’t even put the server in maintenance mode.

I was missing apc.enable_cli=1 in /etc/php/7.4/cli/conf.d/20-apcu.ini although I had APCu enabled in my config.php

I put this in and then restarted apache.

Now I can put the server in maintenance and look at the other issues.

3 Likes

I had a similar problem.

System:
Vmware VM with CentOS 8
PHP 7.3
apache 2.4

Problem:
Upgrade from 20.0.8 to 21.0.1 did not work

Detail:
sudo -u apache php /var/www/nextcloud/updater/updater.phar
worked until:
Should the “occ upgrade” command be executed? [Y/n] Y
then:
PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) in /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php on line 133

The same with any other occ command. (which worked before the interrupted upgrade)

The above proposed work arounds like -d memory_limit=512M or -1 did not work for me.

Reason:
in nextclouds config.php where set:
‘debug’ => ‘true’,
‘loglevel’ => 0,

Solution
just set these variables to:
‘debug’ => ‘false’,
‘loglevel’ => 2,

Run “sudo -u apache php /var/www/nextcloud/occ upgrade” again.

Upgrade was successful !

5 Likes