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

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

Thanks. I do not understand why this helps but it helps for me :slight_smile:
I linked your solution here:
https://github.com/nextcloud/server/issues/25742#issuecomment-817173060
Hope this is ok.

1 Like

Tanks a lot!!! I tried everything els, but this was the only thing working for me on a synology with newest DSM!!

Not sure if it’s been said already or not, but what worked for me was commenting out the memcache settings in the config.php file, running the command, then uncommenting it.

Setting loglevel = > 2 helped. Thanks to @ncuser2! @onny: Could you mark ncuser2 comment as solution as well?

We had a similar problem. The solution we found was to remove the APCu line from config.php and then run the upgrade, but it looks as though updating the php.ini for php 7.4 would work just as well. That’s what we did afterwards, once we worked out what the problem was. The correct way is, I suspect, to put something in config.d, but we just edited config.ini directly — both for the cli and for the apache2 — adding apc.enable_cli=1 . This is mentioned in the Nextcloud manual but it took us a while to work out that it was the source of our woes.

Thanks andreasus, you saved my day with that apc.enable_cli=1

I can add that the fix of enabling apc cli has worked for me. I am also running on TrueNAS, perhaps this is unique to the plugin setup.

very helpful indeed,
Had to add this parameter also in php 7.3

apc cli fixed it for me in nc 21.
but does apc cli bring in other problems with cached cli commands?

Similar, this is what got me back up and running. All attempts at changing the php limits above were not working, but surprisingly this did.

Thanks a ton!

I have just encountered the same problem after upgrading to 21. I’m not stuck in maitenance mode, but cron always runs out of memory. For me also commenting out memcache.local' => '\\OC\\Memcache\\APCu', from /var/www/nextcloud/config/config.php, letting the cron job run, and then uncommenting it again seems to have resolved the problem.

EDIT: actually uncommenting again brings the problem back

Have you tried the solution listed here: [SOLVED] Occ command; PHP Fatal error, Allowed memory size of XXX bytes exhausted - #45 by ro55mo?

Also, documentation is clear with a warning here:
https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/caching_configuration.html#id1

Hope it can help solve your problem

Hi all,
I have the same issue and I solve it with the recommendation. I add my experience with the last update.

I am using the docker-compose “Base version - apache” to build my service from Docker Hub .

After my update to 22 the bug appear with occ.

I did solve the issue by settting by hand the PHP memory limit in the file:

/usr/local/etc/php/conf.d/nextcloud.ini
memory_limit=512M
upload_max_filesize=${PHP_UPLOAD_LIMIT}
post_max_size=${PHP_UPLOAD_LIMIT}

of my app container.

Have a nice solve.

3 Likes

Thank you, the same problem I had after upgrade to v22. The fix worked for me.

Ah many thanks, I was searching for the path to insert this apc.enable_cli=1

Possibly obvious for many but might help others like me.

Cheers

Could you please shortly explain why? It also works for me, but it still cannot work automatically, which is my purpose.

Here it runs ok like 10 minuts, and then the same

I experienced this same issue. What “fixed” it for me was defining memory_limit explicitly on the command line.

sudo -u apache php --define memory_limt=512M ./occ

I find this odd, considering I have memory_limit=512M in my /etc/php.ini, and running php -i | grep memory_limit shows the value set to 512M.