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

Nextcloud version (eg, 20.0.5): 21
Operating system and version (eg, Ubuntu 20.04): ArchLinux x64
Apache or nginx version (eg, Apache 2.4.25): Caddy 2.3
PHP version (eg, 7.4): 8.0.2

The issue you are facing:
After upgrading to Nextcloud 21, I’m unable to run occ anymore:

$ sudo -u http ./occ update
PHP Warning: Module “gd” is already loaded in Unknown on line 0
PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /usr/share/webapps/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php on line 133

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Upgrade to Nextcloud 21
  2. Run ./occ with php8

The output of your Nextcloud log in Admin > Logging:

Noticed nothing exceptional here

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => '****',
  'datadirectory' => '/var/lib/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '21.0.0.18',
  'dbname' => 'nextcloud',
  'dbhost' => 'mysql.pi',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '****',
  'installed' => true,
  'maintenance' => false,
  'loglevel' => 0,
  'cron_log' => true,
  'maxZipInputSize' => 5145728000,
  'allowZipDownload' => true,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'allow_local_remote_servers' => true,
  'trusted_domains' => 
  array (
    0 => 'nextcloud.****',
  ),
  'passwordsalt' => '****',
  'secret' => '****',
  'mail_domain' => '***',
  'mail_smtpmode' => 'php',
  'mail_from_address' => 'nextcloud',
  'trashbin_retention_obligation' => 'auto',
  'updatechecker' => false,
  'app.mail.verify-tls-peer' => false,
);

The output of your Apache/nginx/system log in /var/log/____:

Not relevant in this case

Already tried:

  • Using php7 to launch ./occ, same issue
  • Moving all apps outside of the app directory in case they cause errors
  • Increased PHP memory limit to 512MB and greater, still no effect. Issued php -i to guarantee configured parameter
  • Surprisingly Nextcloud itself managed to perform the upgrade through php-fpm and Caddy via web frontent and is accessible quite well

This issue seems tricky, especially because of this configuration. Would be glad to get some debugging tipps :wink:

Regards
Jonas

13 Likes

Same issue here:

Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 438272 bytes) in /var/www/html/3rdparty/composer/autoload_real.php on line 37

Tried to add missing db indices with “occ db:add-missing-indices”. I’m using docker version (https://github.com/nextcloud/docker/blob/master/.examples/dockerfiles/full/apache/Dockerfile).

Running occ without any parameters gives the same result.

1 Like

Thanks chrisu, unfortunately still getting the same error :frowning:

Sorry, You misunderstood me. I tried to add indices because NC scanner said they are missing.

1 Like

I have the same problem! The web interface is working just fine. Only the occ command runs out of memory.

2 Likes

I was having the same issue, running nextcloud in a docker (compose) setup. My cron-job triggered the command

/usr/bin/docker exec nextcloud_app_1 su - www-data -s /bin/bash -c 'php -f /var/www/html/cron.php'

which was not working. When I changed it to

/usr/bin/docker exec -u www-data nextcloud_app_1 php -f /var/www/html/cron.php

the error went away.

3 Likes

this has nothing to do with the shape of the cron command, when upgraded to nextcloud 21 (from rc2 in my case) the occ command simply runs out of all available memory.
Tried php 7.0 7.3 8.0 nothing changes.
Nothing on the logs, system, php or nextcloud.

This is a BIG problem as without occ the installation is stuck in maintenance mode after the upgrade…

2 Likes

Update broke my installation too. The problem so far is that occ doesn’t do a thing here and always bails out with the same memory error. I tried to give the PHP process 8 GB of memory… nope.

Update 1:
in config/config.php you can disable the maintenance mode - find the line
'maintenance' => true, and set it to ‘false’ and you’re good to go back on the web updater.
cron is still an issue as it relies on occ…

2 Likes

I had the exact same issue.
There is an issue on github there: Allowed memory size of xxx bytes exhausted in current latest-container · Issue #1413 · nextcloud/docker · GitHub
They are mentioning the addition of the -d memory_limit=-1 option to the php command (I suppose setting the limit to an infinite value).
I can confirm that this resolves the issue for me, while waiting for a newer release to fix the issue !

2 Likes

Same issue here, tried with php7.3, php7.4, php.8.0, tried editing memory limit in php.ini & the command line -1, to no avail. occ simply gets killed every time. Thank God I didn’t go through with the browser upgrade, would’ve crashed my install. I just hope this gets fixed in a future release, looking forward to test drive 21.

I limited the memory to 8 GB and it went into ‘OOM’ mode… I don’t think that removing the limit is THE solution as it will just feast on memory. (upadte:) … until the OOM killer sets a stop to it.

1 Like

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

1 Like

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.

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