Cannot declare class OC\Command\CommandJob

Nextcloud version (eg, 20.0.5): 28.0.4
Operating system and version (eg, Ubuntu 20.04): Ubuntu 22.04.03
Apache or nginx version (eg, Apache 2.4.25): nginx/1.24.0
PHP version (eg, 7.4): 8.1.2

The issue you are facing:

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

Steps to replicate it:

  1. sudo -u www-data /usr/bin/php /srv/www/
PHP Fatal error:  Cannot declare class OC\Command\CommandJob, because the name is already in use in /srv/www/ on line 3

Nextcloud instance itself works normally but complains about last background job execution running 7 months (what?!) ago.

I’m running cron.php as a systemd service:

Description=Nextcloud cron.php job

ExecCondition=/usr/bin/php -f /srv/www/ status -e
ExecStart=/usr/bin/php -f /srv/www/

The first time I can see the error in journalctl -u nextcloud-cron.service is 2024-03-20

UPDATE @ 02:44

In my nextcloud.log I could find the following entry:

  "reqId": "f3vl9SsZAHTLOuSpiQJl",
  "level": 3,
  "time": "2023-08-17T15:08:30+00:00",
  "remoteAddr": "",
  "user": "--",
  "app": "PHP",
  "method": "",
  "url": "--",
  "message": "Cannot declare class OC\\Command\\CommandJob, because the name is already in use at /srv/www/",
  "userAgent": "--",
  "version": "",
  "data": {
    "app": "PHP"

So I had this problem since at least :thinking:

UPDATE @ 04:11

I give up. So far I tried:

  1. Upgrading to PHP 8.2
  2. Upgrading to PHP 8.3
  3. Simply rebooting
  4. Restarting Redis
  5. Restarting PostgreSQL
  6. Restarting PHP-FPM
Result of occ integrity:check-core -vvv
$ sudo -u www-data /usr/bin/php8.3 occ integrity:check-core -vvv                                                                                                                                                                                                                  
No errors found
Result of occ setupchecks
$ sudo -u www-data /usr/bin/php8.3 occ setupchecks
                ✓ DAV system address book: No outstanding DAV system address book sync.
                ⚠ Errors in the log: 2068 errors in the logs since March 22, 2024
                ℹ Brute-force Throttle: Your remote address could not be determined.
                ✓ Cron errors: The last cron job ran without errors.
                ✗ Cron last run: Last background job execution ran 7 months ago. Something seems wrong. Check the background job settings.
                ✓ File locking
                ✓ Maintenance window start: Maintenance window to execute heavy background jobs is between 1:00 UTC and 7:00 UTC
                ✓ Memcache: Configured
                ✓ PHP modules
                ✓ Architecture: 64-bit
                ✓ Push notifications - Fair use policy
                ✓ App directories owner: App directories have the correct owner "www-data"
                ✓ Old user imported certificates
                ✓ Code integrity: No altered files
                ℹ Forwarded for headers: Your remote address could not be determined.
                ✓ Old server-side-encryption: Disabled
                ✓ PHP version: You are currently running PHP 8.3.4.
                ✓ Random generator: Secure
                ✓ Database missing columns: None
                ✓ Database missing indices: None
                ✓ Database missing primary keys: None
                ✓ Database pending bigint migrations: None
                ✓ Database version: 12.18 (Ubuntu 12.18-1.pgdg22.04+1)
                ✓ Database transaction isolation level: Read committed
                ✓ Default phone region: PL
                ✓ Email test: Email test was successfully sent
                ✓ Overwrite cli URL: The "overwrite.cli.url" option in your config.php is set to "" which is a correct URL. Suggested URL is "https://localhost".
                ✓ Configuration file access rights: Nextcloud configuration file is writable
                ✓ Internet connectivity
                ✓ JavaScript modules support
                ✓ PHP default charset: UTF-8
                ✓ Freetype: Supported
                ✓ PHP getenv
                ✓ PHP memory limit: ?
                ✓ PHP opcache: Correctly configured
                ✓ PHP "output_buffering" option: Disabled
                ✓ PHP Imagick module

You also opened a bug report:

And since there are already answers from developers, we don’t start here in parallel.