Occ command throws error

Nextcloud version: 25.0.1
PHP version: 8.0.24

The issue you are facing: I am trying to run the occ command. I’ve tried “php occ” and “./occ”, both inside my nextcloud folder. And because it’s not my server I also don’t have access to sudo. I always get this error:

PHP Warning:  Undefined array key "SCRIPT_FILENAME" in /mnt/web115/a2/23/511739323/htdocs/static/cloud/lib/base.php on line 155
PHP Warning:  Undefined array key "SCRIPT_NAME" in /mnt/web115/a2/23/511739323/htdocs/static/cloud/lib/base.php on line 162
PHP Warning:  Undefined array key "SCRIPT_FILENAME" in /mnt/web115/a2/23/511739323/htdocs/static/cloud/lib/base.php on line 163
X-Powered-By: PHP/8.0.24
Content-type: text/html; charset=UTF-8

An unhandled exception has been thrown:
TypeError: OC\AppFramework\Http\Request::getScriptName(): Return value must be of type string, null returned in /mnt/web115/a2/23/511739323/htdocs/static/cloud/lib/private/AppFramework/Http/Request.php:777
Stack trace:
#0 /mnt/web115/a2/23/511739323/htdocs/static/cloud/lib/base.php(171): OC\AppFramework\Http\Request->getScriptName()
#1 /mnt/web115/a2/23/511739323/htdocs/static/cloud/lib/base.php(598): OC::initPaths()
#2 /mnt/web115/a2/23/511739323/htdocs/static/cloud/lib/base.php(1144): OC::init()
#3 /mnt/web115/a2/23/511739323/htdocs/static/cloud/console.php(48): require_once('...')
#4 /mnt/web115/a2/23/511739323/htdocs/static/cloud/occ(11): require_once('...')
#5 {main}

The commands I am trying to run are the following:

occ maintenance:update:htaccess
occ db:add-missing-indices
occ db:convert-filecache-bigint

Is this the first time you’ve seen this error?: No, already occured before, never worked before

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

<?php
$CONFIG = array (
  'instanceid' => '<===>',
  'passwordsalt' => '<===>',
  'secret' => '<===>',
  'trusted_domains' =>
  array (
    0 => '<===>',
  ),
  'datadirectory' => '<===>/clouddata',
  'dbtype' => 'mysql',
  'version' => '25.0.1.1',
  'overwrite.cli.url' => '<===>cloud',
  'dbname' => '<===>',
  'dbhost' => 'r<===>',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => '<===>',
  'dbpassword' => '<===>',
  'installed' => true,
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'ssl',
  'mail_sendmailmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => '<===>',
  'mail_from_address' => '<===>',
  'mail_domain' => '<===>',
  'mail_smtpname' => '<===>',
  'mail_smtppassword' => '<===>',
  'mail_smtpport' => '465',
  'default_language' => 'de',
  'default_locale' => 'de_DE',
  'default_phone_region' => 'DE',
  'knowledgebaseenabled' => false,
  'overwritehost' => '<===>',
  'overwriteprotocol' => 'https',
  'overwrite.cli.url' => '<===>/cloud',
  'htaccess.RewriteBase' => '/cloud',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 0
);

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

21.11.2022 10:35:54 <===> PHP Fatal error:  Uncaught Doctrine\\DBAL\\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [1203] User o8587686 already has more than 'max_user_connections' active connections in <===>/static/cloud/lib/private/DB/Connection.php:139
21.11.2022 10:35:54 <===> Stack trace:
21.11.2022 10:35:54 <===> #0 <===>/static/cloud/3rdparty/doctrine/dbal/src/Connection.php(1519): OC\\DB\\Connection->connect()
21.11.2022 10:35:54 <===> #1 <===>/static/cloud/3rdparty/doctrine/dbal/src/Connection.php(1041): Doctrine\\DBAL\\Connection->getWrappedConnection()
21.11.2022 10:35:54 <===> #2 <===>/static/cloud/lib/private/DB/Connection.php(261): Doctrine\\DBAL\\Connection->executeQuery()
21.11.2022 10:35:54 <===> #3 <===>/static/cloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\\DB\\Connection->executeQuery()
21.11.2022 10:35:54 <===> #4 <===>/static/cloud/lib/private/DB/QueryBuilder/QueryBuilder.php(281): Doctrine\\DBAL\\Query\\QueryBuilder->execute()
21.11.2022 10:35:54 <===> #5 <===>/static/cloud/lib/private/AppConfig.php(411): OC\\DB\\QueryBuilder\\QueryBuilder->execute()
21.11.2022 10:35:54 <===> #6 <===>/static/cloud/lib/private/AppConfig.php(176): OC\\AppConfig->loadConfigValues()
21.11.2022 10:35:54 <===> #7 <===>/static/cloud/lib/private/AppConfig.php(367): OC\\AppConfig->getApps()
21.11.2022 10:35:54 <===> #8 <===>/static/cloud/lib/private/legacy/OC_App.php(965): OC\\AppConfig->getValues()
21.11.2022 10:35:54 <===> #9 <===>/static/cloud/lib/private/Server.php(725): OC_App::getAppVersions()
21.11.2022 10:35:54 <===> #10 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\\Server->OC\\{closure}()
21.11.2022 10:35:54 <===> #11 <===>/static/cloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\\AppFramework\\Utility\\SimpleContainer->OC\\AppFramework\\Utility\\{closure}()
21.11.2022 10:35:54 <===> #12 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\\Container->offsetGet()
21.11.2022 10:35:54 <===> #13 <===>/static/cloud/lib/private/ServerContainer.php(136): OC\\AppFramework\\Utility\\SimpleContainer->query()
21.11.2022 10:35:54 <===> #14 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\\ServerContainer->query()
21.11.2022 10:35:54 <===> #15 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(184): OC\\AppFramework\\Utility\\SimpleContainer->get()
21.11.2022 10:35:54 <===> #16 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\\AppFramework\\Utility\\SimpleContainer->OC\\AppFramework\\Utility\\{closure}()
21.11.2022 10:35:54 <===> #17 <===>/static/cloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\\AppFramework\\Utility\\SimpleContainer->OC\\AppFramework\\Utility\\{closure}()
21.11.2022 10:35:54 <===> #18 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\\Container->offsetGet()
21.11.2022 10:35:54 <===> #19 <===>/static/cloud/lib/private/ServerContainer.php(136): OC\\AppFramework\\Utility\\SimpleContainer->query()
21.11.2022 10:35:54 <===> #20 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\\ServerContainer->query()
21.11.2022 10:35:54 <===> #21 <===>/static/cloud/lib/private/Server.php(1119): OC\\AppFramework\\Utility\\SimpleContainer->get()
21.11.2022 10:35:54 <===> #22 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\\Server->OC\\{closure}()
21.11.2022 10:35:54 <===> #23 <===>/static/cloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\\AppFramework\\Utility\\SimpleContainer->OC\\AppFramework\\Utility\\{closure}()
21.11.2022 10:35:54 <===> #24 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\\Container->offsetGet()
21.11.2022 10:35:54 <===> #25 <===>/static/cloud/lib/private/ServerContainer.php(136): OC\\AppFramework\\Utility\\SimpleContainer->query()
21.11.2022 10:35:54 <===> #26 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\\ServerContainer->query()
21.11.2022 10:35:54 <===> #27 <===>/static/cloud/lib/private/Server.php(2069): OC\\AppFramework\\Utility\\SimpleContainer->get()
21.11.2022 10:35:54 <===> #28 <===>/static/cloud/lib/private/Files/View.php(117): OC\\Server->getLockingProvider()
21.11.2022 10:35:54 <===> #29 <===>/static/cloud/lib/private/Server.php(462): OC\\Files\\View->__construct()
21.11.2022 10:35:54 <===> #30 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\\Server->OC\\{closure}()
21.11.2022 10:35:54 <===> #31 <===>/static/cloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\\AppFramework\\Utility\\SimpleContainer->OC\\AppFramework\\Utility\\{closure}()
21.11.2022 10:35:54 <===> #32 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\\Container->offsetGet()
21.11.2022 10:35:54 <===> #33 <===>/static/cloud/lib/private/ServerContainer.php(136): OC\\AppFramework\\Utility\\SimpleContainer->query()
21.11.2022 10:35:54 <===> #34 <===>/static/cloud/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\\ServerContainer->query()
21.11.2022 10:35:54 <===> #35 <===>/static/cloud/lib/private/Server.php(1471): OC\\AppFramework\\Utility\\SimpleContainer->get()
21.11.2022 10:35:54 <===> #36 <===>/static/cloud/lib/base.php(617): OC\\Server->boot()
21.11.2022 10:35:54 <===> #37 <===>/static/cloud/lib/base.php(1144): OC::init()
21.11.2022 10:35:54 <===> #38 <===>/static/cloud/ocs/v1.php(31): require_once('...')
21.11.2022 10:35:54 <===> #39 <===>/static/cloud/ocs/v2.php(23): require_once('...')
21.11.2022 10:35:54 <===> #40 {main}
21.11.2022 10:35:54 <===> thrown in <===>/static/cloud/lib/private/DB/Connection.php on line 139

Output errors in nextcloud.log in /var/www/ or as admin user in top right menu, filtering for errors. Use a pastebin service if necessary.

{"reqId":"<===>","level":2,"time":"2022-11-21T08:23:07+00:00","remoteAddr":"<===>","user":"--","app":"no app in context","method":"PROPFIND","url":"/cloud/index.php","message":"Could not detect any host in https:///cloud/data/htaccesstest.txt","userAgent":"Mozilla/5.0 (Macintosh) mirall/3.6.2git (build 12294) (Nextcloud, osx-22.1.0 ClientArchitecture: x86_64 OsArchitecture: x86_64)","version":"","data":[]}
{"reqId":"<===>","level":2,"time":"2022-11-21T08:23:07+00:00","remoteAddr":"<===>","user":"--","app":"no app in context","method":"PROPFIND","url":"/cloud/index.php","message":"Could not detect any host in http:///cloud/data/htaccesstest.txt","userAgent":"Mozilla/5.0 (Macintosh) mirall/3.6.2git (build 12294) (Nextcloud, osx-22.1.0 ClientArchitecture: x86_64 OsArchitecture: x86_64)","version":"","data":[]}
{"reqId":"<===>","level":2,"time":"2022-11-21T08:23:24+00:00","remoteAddr":"<===>","user":"--","app":"no app in context","method":"PROPFIND","url":"/cloud/index.php","message":"Could not detect any host in https:///cloud/data/htaccesstest.txt","userAgent":"Mozilla/5.0 (Macintosh) mirall/3.6.2git (build 12294) (Nextcloud, osx-22.1.0 ClientArchitecture: x86_64 OsArchitecture: x86_64)","version":"","data":[]}
{"reqId":"<===>","level":2,"time":"2022-11-21T08:23:24+00:00","remoteAddr":"<===>","user":"--","app":"no app in context","method":"PROPFIND","url":"/cloud/index.php","message":"Could not detect any host in http:///cloud/data/htaccesstest.txt","userAgent":"Mozilla/5.0 (Macintosh) mirall/3.6.2git (build 12294) (Nextcloud, osx-22.1.0 ClientArchitecture: x86_64 OsArchitecture: x86_64)","version":"","data":[]}

I replaced possible sensitive information with “<===>”