Fresh install of server 31 & OC\User\Database::countUsers() error

The Basics

  • Nextcloud Server version:
    • 31
  • Operating system and version:
    • Cloudlinux
  • Web server and version:
    • Litespeed
  • PHP version:
    • 8.2
  • Is this the first time you’ve seen this error? (Yes / No):
    • Yes
  • When did this problem seem to first start?
    • immediately after fresh install
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • webinstaller
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • No

Summary of the issue you are facing:

After installation with webinstaller I can log into admin and all is working, but I get error for:

  • administration > overview (/index.php/settings/admin/overview)
  • acccounts (index.php/settings/users)

I also tried installation through softacolous script installer on my shared webhost and got same error.

Log entries

Nextcloud

Logging* screen or from your `nextcloud.log’

Exception
OC\User\Database::countUsers(): Return value must be of type int|false, string returned in file '/home/user/domains/domain.com/public_html/lib/private/User/Database.php' line 475

Configuration

Nextcloud

Default config.

Apps

Default config.

What could be the reason :thinking:

What is the EXACT error you are getting?

In shared environments some accesses might be restricted, therefore it is essential to provide as much information about your enviornment as possible.

Don’t assume that everyone knows your environment or what you understand under “Default config”. Please provide DETAILED information about your setup.

1 Like

Thanks j-ed for your response.
Following is brief information and I will provide details later.

I get internal server error

And in error log

Exception
OC\User\Database::countUsers(): Return value must be of type int|false, string returned in file ‘/home/user/domains/domain.com/public_html/lib/private/User/Database.php’ line 475

Any clues what to do?

Please provide the full raw log entry.

Default config.

There’s really no such as thing as a default configuration. Given this error is database related, we need your config.

I have Installed ver 30 and it works on same server… :smiley:
So it seems there is a bug in ver 31. :thinking:

Maybe. I don’t see this in my v31 test instances.

No way to know the cause without the full stack trace / log entry, your config, etc. as already noted.

I have now upgraded to v31 and got same errors :upside_down_face:
Sending further details.

config:list system

{
    "system": {
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "localhost",
            "***REMOVED SENSITIVE VALUE***"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "mysql",
        "version": "31.0.0.18",
        "overwrite.cli.url": "http:\/\/localhost",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "maintenance": false,
        "loglevel": 2
    }
}

Log error app index

{"reqId":"W8dStA8G1JeMqxbVxR4W","level":3,"time":"2025-03-05T22:18:15+00:00","remoteAddr":"***.***.***.***","user":"admin","app":"index","method":"GET","url":"/index.php/settings/users","message":"OC\\User\\Database::countUsers(): Return value must be of type int|false, string returned in file '/path/to/nextcloud/lib/private/User/Database.php' line 475","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0","version":"31.0.0.18","exception":{"Exception":"Exception","Message":"OC\\User\\Database::countUsers(): Return value must be of type int|false, string returned in file '/path/to/nextcloud/lib/private/User/Database.php' line 475","Code":0,"Trace":[{"file":"/path/to/nextcloud/lib/private/AppFramework/App.php","line":161,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/path/to/nextcloud/lib/private/Route/Router.php","line":307,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/path/to/nextcloud/lib/base.php","line":1018,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/path/to/nextcloud/index.php","line":24,"function":"handleRequest","class":"OC","type":"::"}],"File":"/path/to/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","Line":146,"Previous":{"Exception":"TypeError","Message":"OC\\User\\Database::countUsers(): Return value must be of type int|false, string returned","Code":0,"Trace":[{"file":"/path/to/nextcloud/lib/private/User/Manager.php","line":475,"function":"countUsers","class":"OC\\User\\Database","type":"->"},{"file":"/path/to/nextcloud/apps/settings/lib/Controller/UsersController.php","line":148,"function":"countUsers","class":"OC\\User\\Manager","type":"->"},{"file":"/path/to/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":200,"function":"usersList","class":"OCA\\Settings\\Controller\\UsersController","type":"->"},{"file":"/path/to/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":114,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/path/to/nextcloud/lib/private/AppFramework/App.php","line":161,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/path/to/nextcloud/lib/private/Route/Router.php","line":307,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/path/to/nextcloud/lib/base.php","line":1018,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/path/to/nextcloud/index.php","line":24,"function":"handleRequest","class":"OC","type":"::"}],"File":"/path/to/nextcloud/lib/private/User/Database.php","Line":475},"message":"OC\\User\\Database::countUsers(): Return value must be of type int|false, string returned in file '/path/to/nextcloud/lib/private/User/Database.php' line 475","exception":[],"CustomMessage":"OC\\User\\Database::countUsers(): Return value must be of type int|false, string returned in file '/path/to/nextcloud/lib/private/User/Database.php' line 475"},"id":"67c8cdc444bf6"}

Log error app core

{"reqId":"KMVgeoqL5Zfk34ohkCab","level":3,"time":"2025-03-05T22:05:31+00:00","remoteAddr":"","user":false,"app":"core","method":"","url":"--","message":"Error while running background job OCA\\Support\\BackgroundJobs\\CheckSubscription (id: 1, arguments: null)","userAgent":"--","version":"31.0.0.18","exception":{"Exception":"TypeError","Message":"OC\\User\\Database::countUsers(): Return value must be of type int|false, string returned","Code":0,"Trace":[{"file":"/path/to/nextcloud/apps/support/lib/Service/SubscriptionService.php","line":78,"function":"countUsers","class":"OC\\User\\Database","type":"->"},{"file":"/path/to/nextcloud/apps/support/lib/Service/SubscriptionService.php","line":232,"function":"getUserCount","class":"OCA\\Support\\Service\\SubscriptionService","type":"->"},{"file":"/path/to/nextcloud/apps/support/lib/Service/SubscriptionService.php","line":294,"function":"getSubscriptionInfo","class":"OCA\\Support\\Service\\SubscriptionService","type":"->"},{"file":"/path/to/nextcloud/apps/support/lib/BackgroundJobs/CheckSubscription.php","line":32,"function":"checkSubscription","class":"OCA\\Support\\Service\\SubscriptionService","type":"->"},{"file":"/path/to/nextcloud/lib/public/BackgroundJob/Job.php","line":61,"function":"run","class":"OCA\\Support\\BackgroundJobs\\CheckSubscription","type":"->"},{"file":"/path/to/nextcloud/lib/public/BackgroundJob/TimedJob.php","line":88,"function":"start","class":"OCP\\BackgroundJob\\Job","type":"->"},{"file":"/path/to/nextcloud/lib/public/BackgroundJob/TimedJob.php","line":75,"function":"start","class":"OCP\\BackgroundJob\\TimedJob","type":"->"},{"file":"/path/to/nextcloud/core/Command/Background/JobWorker.php","line":129,"function":"execute","class":"OCP\\BackgroundJob\\TimedJob","type":"->"},{"file":"/path/to/nextcloud/3rdparty/symfony/console/Command/Command.php","line":326,"function":"execute","class":"OC\\Core\\Command\\Background\\JobWorker","type":"->"},{"file":"/path/to/nextcloud/core/Command/Base.php","line":161,"function":"run","class":"Symfony\\Component\\Console\\Command\\Command","type":"->"},{"file":"/path/to/nextcloud/3rdparty/symfony/console/Application.php","line":1078,"function":"run","class":"OC\\Core\\Command\\Base","type":"->"},{"file":"/path/to/nextcloud/3rdparty/symfony/console/Application.php","line":324,"function":"doRunCommand","class":"Symfony\\Component\\Console\\Application","type":"->"},{"file":"/path/to/nextcloud/3rdparty/symfony/console/Application.php","line":175,"function":"doRun","class":"Symfony\\Component\\Console\\Application","type":"->"},{"file":"/path/to/nextcloud/lib/private/Console/Application.php","line":187,"function":"run","class":"Symfony\\Component\\Console\\Application","type":"->"},{"file":"/path/to/nextcloud/console.php","line":87,"function":"run","class":"OC\\Console\\Application","type":"->"},{"file":"/path/to/nextcloud/occ","line":11,"args":["/path/to/nextcloud/console.php"],"function":"require_once"}],"File":"/path/to/nextcloud/lib/private/User/Database.php","Line":475,"message":"Error while running background job OCA\\Support\\BackgroundJobs\\CheckSubscription (id: 1, arguments: null)","exception":[],"CustomMessage":"Error while running background job OCA\\Support\\BackgroundJobs\\CheckSubscription (id: 1, arguments: null)"},"id":"67c8cdce3fcda"}

app:list

Enabled:
  - activity: 4.0.0
  - app_api: 5.0.2
  - bruteforcesettings: 4.0.0
  - circles: 31.0.0-dev.0
  - cloud_federation_api: 1.14.0
  - comments: 1.21.0
  - contactsinteraction: 1.12.0
  - dashboard: 7.11.0
  - dav: 1.33.0
  - federatedfilesharing: 1.21.0
  - federation: 1.21.0
  - files: 2.3.1
  - files_downloadlimit: 4.0.0
  - files_pdfviewer: 4.0.0
  - files_reminders: 1.4.0
  - files_sharing: 1.23.1
  - files_trashbin: 1.21.0
  - files_versions: 1.24.0
  - firstrunwizard: 4.0.0
  - logreader: 4.0.0
  - lookup_server_connector: 1.19.0
  - nextcloud_announcements: 3.0.0
  - notifications: 4.0.0
  - oauth2: 1.19.1
  - password_policy: 3.0.0
  - photos: 4.0.0-dev.1
  - privacy: 3.0.0
  - profile: 1.0.0
  - provisioning_api: 1.21.0
  - recommendations: 4.0.0
  - related_resources: 2.0.0
  - serverinfo: 3.0.0
  - settings: 1.14.0
  - sharebymail: 1.21.0
  - support: 3.0.0
  - survey_client: 3.0.0
  - systemtags: 1.21.1
  - text: 5.0.0
  - theming: 2.6.1
  - twofactor_backupcodes: 1.20.0
  - updatenotification: 1.21.0
  - user_status: 1.11.0
  - viewer: 4.0.0
  - weather_status: 1.11.0
  - webhook_listeners: 1.2.0
  - workflowengine: 2.13.0
Disabled:
  - admin_audit: 1.21.0
  - encryption: 2.19.0
  - files_external: 1.23.0
  - suspicious_login: 9.0.1
  - twofactor_nextcloud_notification: 5.0.0
  - twofactor_totp: 13.0.0-dev.0
  - user_ldap: 1.22.0

Any ideas :thinking:

I found a commit which was released in v31 and is related to countUsers.
Can this be an issue? :thinking:

Hi Miha,
I upgraded from 29 to 30 without any issue, then from 30 to 31 and I have the exact same symptoms. Server error whenever I try to access the Accounts from the Admin menu, or the overview from admin settings.
My journal logs also point to the same Database.php, line 475, returning an incorrect type.

If you need access to the settings, one mildly dirty way to do so is to change the infamous line 475 of /lib/private/User/database.php to force the correct type to be returned:

		//return $result->fetchOne();
		return ($result->fetchOne() !== false) ? (int) $result->fetchOne() : false;

I no longer have errors, but of course this is just a temporary fix!

EDIT: changed my very dirty workaround to a mildly dirty one

I reverted to v30, and no problem.

@Miha, I opened a bug report on github, hopefully we can get help there!

1 Like