Unable to run occ on command line - PHP fatal error memory exhausted in autoreload_real.php

Hi all! Love what you are doing here and am super appreciative of the community support you are providing to each other. I hope to become an active member here. NC21 is sweet! :heart_eyes_cat: I’d be grateful for any guidance.

Nextcloud version (eg, 20.0.5): 21.0.1
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): Apache/2.4.41 (Ubuntu)
PHP version (eg, 7.4): 7.4.3

Since upgrading my digital ocean droplet from an old version of Ubuntu and then NC from an old version, I am getting a similar problem to [SOLVED] Occ command; PHP Fatal error, Allowed memory size of XXX bytes exhausted and tried everything suggested in that topic with no luck. That’s a valuable topic but confusing to look at, and the error message described in the OP and by some of the people replying there is different from my own.

My error message when I run occ is below. Otherwise the upgrade appears to be have been very successful and everything seems to be working very well.

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

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

Steps to replicate it:

  1. from CLI, run sudo -u www-data php -f /var/www/nextcloud/occ

The output of your Nextcloud log in Admin > Logging:

nothing relevant

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

<?php
$CONFIG = array (
  'instanceid' => 'nnn',
  'passwordsalt' => 'nnn',
  'secret' => 'nnn',
  'trusted_domains' => 
  array (
    0 => 'nextcloud.nnn',
  ),
  'datadirectory' => '/mnt/volume-nyc3-01/nextcloud',
  'overwrite.cli.url' => 'nnn',
  'dbtype' => 'mysql',
  'version' => '21.0.1.1',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nnn',
  'dbpassword' => 'nnn',
  'logtimezone' => 'UTC',
  'installed' => true,
  'htaccess.RewriteBase' => '/',
  'mail_from_address' => 'nnn',
  'mail_smtpmode' => 'smtp',
  'mail_domain' => 'nnn',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'nnn',
  'mail_smtpname' => 'nnn',
  'mail_smtppassword' => 'nnn',
  'mail_smtpport' => '25',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'mysql.utf8mb4' => true,
  'default_phone_region' => 'US',
  'debug' => false,
);

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

nothing relevant

There are some warnings on the admin overview still that I am concerned about.

1 Like

Hi Tobias!

Sounds much like what I’m experiencing on my nextcloud instance. I just created a similar topic myself.
https://help.nextcloud.com/t/newly-upgraded-nc-21-0-1-runs-oom-during-cron-and-process-gets-killed/114687/2

I wonder if we are facing the same issue, or if its a different problem.

1 Like

Thanks for reaching out! I don’t know if our problems are related. What happens when you run occ from the command line?

Besides not being able to run occ my server is fine as far as I can tell.

1 Like

Yes when running occ (tried enabling maintenance mode), my memory got exhausted, so same effect as when cron runs.

Can you try removing your APCu cache from your config, restart PHP engine and retry?

Thanks for helping me! Which config do you mean? It’s referenced in several places. And how do I restart the php engine?

Hi Tobias,

I solved my problem by using [SOLVED] Occ command; PHP Fatal error, Allowed memory size of XXX bytes exhausted - #17 by andreasus (comment 17)

The config under the correct PHP version solved that. My OCC stop OOM errors.

1 Like

awesome! good for you, @denNorske! Thanks for updating me. Unfortunately that does not work for me.

/etc/php/7.4/cli/conf.d/20-apcu.ini contains just this:

extension=apcu.so
apc.enable_cli=1

I’ve also tried adding this apc.enable_cli=1 to /etc/php/7.4/cli/php.ini with no success. Removed it from there again now.

my /var/www/nextcloud/config/config.php contains this line. When I try removing the line entirely, I get a notice on the admin overview panel. Trying occ command without it has no effect on the error I am getting.

  'memcache.local' => '\\OC\\Memcache\\APCu',

Is it possible something entirely different is going on here, like maybe file permissions or something missing from the config file? I did just recently upgrade from a very old version so maybe there’s some stray issue.

I have a suspicion, and that is you are running the commands with “php” which runs a different version. What does sudo -u www-data php -v output for you?

Can you try adding this to the config;
apc.enable_cli=1
in the
/etc/php/7.4/cli/conf.d/20-apcu.ini
file again (because it’s needed)

and then run this (ensure it’s 7.4, so run “php7.4” and Max 1 GB Memory):

sudo -u www-data PHP_MEMORY_LIMIT=1G php7.4 -f /var/www/nextcloud/occ

Let me know how it goes :slight_smile:

1 Like
root@nextcloud:/var/www/nextcloud# sudo -u www-data php -v
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

That is still in place. I just removed it from /etc/php/7.4/cli/php.ini.

Same error. :frowning:

I think I had tried this combination of things already. I tried pretty much everything suggested in the [SOLVED] Occ command; PHP Fatal error, Allowed memory size of XXX bytes exhausted topic.

Driving me cray-zee! :crazy_face:

I am still stuck on this, finding no solution despite lots of research and experimenting with settings. I’d really appreciate any guidance with troubleshooting!

@chrisu did you ever get your occ working from the command line? I see you and I had exactly the same error message, about the same file and location.

Yes, occ command was working fine before upgrade to 21 version. Now the only way to run it is:
docker exec nextcloud su - www-data -s /bin/bash -c 'php -d memory_limit=-1 -f /var/www/html/occ' - that’s how I was able to add missing db indices. Any other method do not work for me.

1 Like

Wow! I owe you a :beers: - you shared one version of all the advice I’ve read that for some reason works!? This is what I run. I guess I will update cron so it runs this command instead. :man_shrugging:

sudo -u www-data php -d memory_limit=-1 -f /var/www/nextcloud/occ

Incidentally, I figured out that my problem was related to a typo I made in my /etc/php/7.4/cli/php.ini file. Having fixed the typo, now I am able to run sudo -u www-data /var/www/nextcloud/occ as usual, without error. :rocket:

I had written

memory_limit = 2GB

instead of the correct

memory_limit = 2G
1 Like

Hello @TobiasEigen I see that the command runs me an error with the following message

root@nextcloud:/var/www/html# sudo -u www-data php -d memory_limit=-1 -f /var/www/nextcloud/occ
Could not open input file: /var/www/nextcloud/occ

Hi @Hrishkesh and welcome to our community! :wave:

There’s no need to @ mention specific users when replying to topics… because I am in the convo already I will be notified.

The error you pasted seems to indicate that the file doesn’t exist in that location, or that the user www-data is not able to run it. Maybe you have a different setup on your server, with a different user?

This is an old topic and the instructions are a bit outdated… I now use php 8.1 on my server.

Hi Tobias,
Thank you for that quick reply, Even I use the version php 8.1.
However I’m able to run OCC command somehow.
But I have another question I can’t run command migrations from OCC is it there for the latest version of Nextcloud (Current version I’m using is 24.0.1)
I can share the list of commands below from OCC

Nextcloud 24.0.1

Usage:
command [options] [arguments]

Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
–ansi Force ANSI output
–no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
–no-warnings Skip global warnings, show command output only
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
check check dependencies of the server environment
help Display help for a command
list List commands
status show some status information
upgrade run upgrade routines after installation of a new release. The release has to be installed before.
activity
activity:send-mails Sends the activity notification mails
app
app:check-code check code to be compliant
app:disable disable an app
app:enable enable an app
app:getpath Get an absolute path to the app directory
app:install install an app
app:list List all available apps
app:remove remove an app
app:update update an app or all apps
background
background:ajax Use ajax to run background jobs
background:cron Use cron to run background jobs
background:webcron Use webcron to run background jobs
background-job
background-job:execute Execute a single background job manually
broadcast
broadcast:test test the SSE broadcaster
circles
circles:check Checking your configuration
circles:maintenance Clean stuff, keeps the app running
circles:manage:config edit config/type of a Circle
circles:manage:create create a new circle
circles:manage:destroy destroy a circle by its ID
circles:manage:details get details about a circle by its ID
circles:manage:edit edit displayName or description of a Circle
circles:manage:join emulate a user joining a Circle
circles:manage:leave simulate a user joining a Circle
circles:manage:list listing current circles
circles:manage:setting edit setting for a Circle
circles:members:add Add a member to a Circle
circles:members:details get details about a member by its ID
circles:members:level Change the level of a member from a Circle
circles:members:list listing Members from a Circle
circles:members:remove remove a member from a circle
circles:members:search Change the level of a member from a Circle
circles:memberships index and display memberships for local and federated users
circles:remote remote features
circles:shares:files listing shares files
circles:sync Sync Circles and Members
circles:test testing some features
config
config:app:delete Delete an app config value
config:app:get Get an app config value
config:app:set Set an app config value
config:import Import a list of configs
config:list List all configs
config:system:delete Delete a system config value
config:system:get Get a system config value
config:system:set Set a system config value
dav
dav:create-addressbook Create a dav addressbook
dav:create-calendar Create a dav calendar
dav:delete-calendar Delete a dav calendar
dav:list-calendars List all calendars of a user
dav:move-calendar Move a calendar from an user to another
dav:remove-invalid-shares Remove invalid dav shares
dav:retention:clean-up
dav:send-event-reminders Sends event reminders
dav:sync-birthday-calendar Synchronizes the birthday calendar
dav:sync-system-addressbook Synchronizes users to the system addressbook
db
db:add-missing-columns Add missing optional columns to the database tables
db:add-missing-indices Add missing indices to the database tables
db:add-missing-primary-keys Add missing primary keys to the database tables
db:convert-filecache-bigint Convert the ID columns of the filecache to BigInt
db:convert-mysql-charset Convert charset of MySQL/MariaDB to use utf8mb4
db:convert-type Convert the Nextcloud database to the newly configured one
encryption
encryption:change-key-storage-root Change key storage root
encryption:decrypt-all Disable server-side encryption and decrypt all files
encryption:disable Disable encryption
encryption:enable Enable encryption
encryption:encrypt-all Encrypt all files for all users
encryption:list-modules List all available encryption modules
encryption:migrate-key-storage-format Migrate the format of the keystorage to a newer format
encryption:set-default-module Set the encryption default module
encryption:show-key-storage-root Show current key storage root
encryption:status Lists the current status of encryption
federation
federation:sync-addressbooks Synchronizes addressbooks of all federated clouds
files
files:cleanup cleanup filecache
files:recommendations:recommend
files:repair-tree Try and repair malformed filesystem tree structures
files:scan rescan filesystem
files:scan-app-data rescan the AppData folder
files:transfer-ownership All files and folders are moved to another user - outgoing shares and incoming user file shares (optionally) are moved as well.
group
group:add Add a group
group:adduser add a user to a group
group:delete Remove a group
group:info Show information about a group
group:list list configured groups
group:removeuser remove a user from a group
groupfolders
groupfolders:create Create a new group folder
groupfolders:delete Delete group folder
groupfolders:expire Trigger expiry of versions and trashbin for files stored in group folders
groupfolders:group Edit the groups that have access to a group folder
groupfolders:list List the configured group folders
groupfolders:permissions Configure advanced permissions for a configured group folder
groupfolders:quota Edit the quota of a configured group folder
groupfolders:rename Rename group folder
groupfolders:scan Scan a group folder for outside changes
groupfolders:trashbin:cleanup Empty the groupfolder trashbin
integrity
integrity:check-app Check integrity of an app using a signature.
integrity:check-core Check integrity of core code using a signature.
integrity:sign-app Signs an app using a private key.
integrity:sign-core Sign core using a private key.
l10n
l10n:createjs Create javascript translation files for a given app
log
log:file manipulate logging backend
log:manage manage logging configuration
log:tail Tail the nextcloud logfile
log:watch Watch the nextcloud logfile
maintenance
maintenance:data-fingerprint update the systems data-fingerprint after a backup is restored
maintenance:mimetype:update-db Update database mimetypes and update filecache
maintenance:mimetype:update-js Update mimetypelist.js
maintenance:mode set maintenance mode
maintenance:repair repair this installation
maintenance:theme:update Apply custom theme changes
maintenance:update:htaccess Updates the .htaccess file
notification
notification:generate Generate a notification for the given user
notification:test-push Generate a notification for the given user
preview
preview:repair distributes the existing previews into subfolders
preview:reset-rendered-texts Deletes all generated avatars and previews of text and md files
security
security:bruteforce:reset resets bruteforce attemps for given IP address
security:certificates list trusted certificates
security:certificates:import import trusted certificate in PEM format
security:certificates:remove remove trusted certificate
serverinfo
serverinfo:update-storage-statistics Triggers an update of the counts related to storages used in serverinfo
sharing
sharing:cleanup-remote-storages Cleanup shared storage entries that have no matching entry in the shares_external table
sharing:expiration-notification Notify share initiators when a share will expire the next day.
tag
tag:add Add new tag
tag:delete delete a tag
tag:edit edit tag attributes
tag:list list tags
text
text:reset Reset a text document
theming
theming:config Set theming app config values
trashbin
trashbin:cleanup Remove deleted files
trashbin:expire Expires the users trashbin
trashbin:restore Restore all deleted files
trashbin:size Configure the target trashbin size
twofactorauth
twofactorauth:cleanup Clean up the two-factor user-provider association of an uninstalled/removed provider
twofactorauth:disable Disable two-factor authentication for a user
twofactorauth:enable Enable two-factor authentication for a user
twofactorauth:enforce Enabled/disable enforced two-factor authentication
twofactorauth:state Get the two-factor authentication (2FA) state of a user
update
update:check Check for server and app updates
user
user:add adds a user
user:add-app-password Add app password for the named user
user:delete deletes the specified user
user:disable disables the specified user
user:enable enables the specified user
user:export Export a user.
user:import Import a user.
user:info show user info
user:lastseen shows when the user was logged in last time
user:list list configured users
user:report shows how many users have access
user:resetpassword Resets the password of the named user
user:setting Read and modify user settings
versions
versions:cleanup Delete versions
versions:expire Expires the users file versions
workflows
workflows:list Lists configured workflows

Glad you got occ working! I have no idea about your other question about migrations, sorry. Maybe try the search (top right corner), installation instructions, and starting a new topic. Your questions here have nothing to do with this topic which is old and long since solved.

I am on the same version of nextcloud as you.