Run occ on CentOS 6

I installed Nextcloud on a CentOS 6 VPS with cPanel. I need to scan for new files, so I logged in as my root user and ran the command sudo -u apache php occ files:scan --all. This command does not output the expected result, it outputs 500 error.

Status: 500 Internal Server Error
Set-Cookie: ocbm3u12n9nd=ap7difp6l22e2qmut297un90k4; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: oc_sessionPassphrase=sJNY2LaDiu1nZQn4%2BoOal4V0ra4ziua7hQNc0JCEXsOsq4AP8P2Z1%2FXFApBo0%2Bml90ZniZ92DAJFVcUGwB1AgRU5RI771OToO6d%2FCFG2rnRK6ZKa8U2d%2FS2q5%2BMuEjLs; pjLs; path=/; HttpOnly
Content-Type: text/plain; charset=utf-8

Cannot write into "config" directory! This can usually be fixed by giving the webserver write access to the config directory. See https://docs.nextcloud.com/server/12/go.php?tophp?to=admin-dir_permissions

And this is in the terminal:

PHP Warning:  fileperms(): stat failed for /home/user/public_html/dev/nextcloud2/data/nextcloud.log in /home/user/public_html/dev/nextcloud2/lib/private/Log/File.php on line 133
{"reqId":"3xi4WbJhLZ1010N9qdbr","level":3,"time":"2018-04-17T17:45:59+00:00","remoteAddr":"","user":"--","app":"PHP","method":"--","url":"--","message":"fileperms(): stat failed for \/home\/user\/public_html\/dev\/nextcloud2\/data\/nextcloud.log at \/home\/user\/public_html\/dev\/nextcloud2\/lib\/private\/Log\/File.php#133","userAgent":"--","version":"12.0.6.1"}
{"reqId":"3xi4WbJhLZ1010N9qdbr","level":3,"time":"2018-04-17T17:45:59+00:00","remoteAddr":"","user":"--","app":"no app in context","method":"--","url":"--","message":"$absolutePath must be relative to \"files\", value is \"%s\"","userAgent":"--","version":"12.0.6.1"}
PHP Warning:  fileperms(): stat failed for /home/user/public_html/dev/nextcloud2/data/nextcloud.log in /home/user/public_html/dev/nextcloud2/lib/private/Log/File.php on line 133
{"reqId":"3xi4WbJhLZ1010N9qdbr","level":3,"time":"2018-04-17T17:45:59+00:00","remoteAddr":"","user":"--","app":"PHP","method":"--","url":"--","message":"fileperms(): stat failed for \/home\/user\/public_html\/dev\/nextcloud2\/data\/nextcloud.log at \/home\/user\/public_html\/dev\/nextcloud2\/lib\/private\/Log\/File.php#133","userAgent":"--","version":"12.0.6.1"}
{"reqId":"3xi4WbJhLZ1010N9qdbr","level":3,"time":"2018-04-17T17:45:59+00:00","remoteAddr":"","user":"--","app":"core","method":"--","url":"--","message":"Cannot write into \"config\" directory! This can usually be fixed by giving the webserver write access to the config directory. See https:\/\/docs.nextcloud.com\/server\/12\/go.php?to=admin-dir_permissions","userAgent":"--","version":"12.0.6.1"}
PHP Warning:  fileperms(): stat failed for /home/user/public_html/dev/nextcloud2/data/nextcloud.log in /home/user/public_html/dev/nextcloud2/lib/private/Log/File.php on line 133
{"reqId":"3xi4WbJhLZ1010N9qdbr","level":3,"time":"2018-04-17T17:45:59+00:00","remoteAddr":"","user":"--","app":"PHP","method":"--","url":"--","message":"fileperms(): stat failed for \/home\/user\/public_html\/dev\/nextcloud2\/data\/nextcloud.log at \/home\/user\/public_html\/dev\/nextcloud2\/lib\/private\/Log\/File.php#133","userAgent":"--","version":"12.0.6.1"}
{"reqId":"3xi4WbJhLZ1010N9qdbr","level":3,"time":"2018-04-17T17:45:59+00:00","remoteAddr":"","user":"--","app":"core","method":"--","url":"--","message":"Exception: {\"Exception\":\"OCP\\\\Lock\\\\LockedException\",\"Message\":\"\\\"\\\/files_encryption\\\" is locked\",\"Code\":0,\"Trace\":\"#0 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Files\\\/View.php(1153): OC\\\\Files\\\\View->changeLock('\\\/files_encrypti...', 2)\\n#1 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Files\\\/View.php(269): OC\\\\Files\\\\View->basicOperation('mkdir', '\\\/files_encrypti...', Array)\\n#2 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Encryption\\\/Keys\\\/Storage.php(370): OC\\\\Files\\\\View->mkdir('\\\/files_encrypti...')\\n#3 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Encryption\\\/Keys\\\/Storage.php(230): OC\\\\Encryption\\\\Keys\\\\Storage->keySetPreparation('\\\/files_encrypti...')\\n#4 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Encryption\\\/Keys\\\/Storage.php(131): OC\\\\Encryption\\\\Keys\\\\Storage->setKey('\\\/files_encrypti...', '-----BEGIN PUBL...')\\n#5 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/apps\\\/encryption\\\/lib\\\/KeyManager.php(164): OC\\\\Encryption\\\\Keys\\\\Storage->setSystemUserKey('pubShare_94f650...', '-----BEGIN PUBL...', 'OC_DEFAULT_MODU...')\\n#6 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/apps\\\/encryption\\\/lib\\\/Users\\\/Setup.php(86): OCA\\\\Encryption\\\\KeyManager->validateShareKey()\\n#7 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/apps\\\/encryption\\\/lib\\\/AppInfo\\\/Application.php(73): OCA\\\\Encryption\\\\Users\\\\Setup->setupSystem()\\n#8 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/apps\\\/encryption\\\/appinfo\\\/app.php(30): OCA\\\\Encryption\\\\AppInfo\\\\Application->__construct(Array, true)\\n#9 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/legacy\\\/app.php(218): require_once('\\\/home\\\/user...')\\n#10 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/legacy\\\/app.php(151): OC_App::requireAppFile('encryption')\\n#11 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/legacy\\\/app.php(124): OC_App::loadApp('encryption')\\n#12 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/legacy\\\/util.php(185): OC_App::loadApps(Array)\\n#13 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Files\\\/Filesystem.php(264): OC_Util::setupFS('')\\n#14 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Server.php(238): OC\\\\Files\\\\Filesystem::getMountManager(NULL)\\n#15 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/3rdparty\\\/pimple\\\/pimple\\\/src\\\/Pimple\\\/Container.php(113): OC\\\\Server->OC\\\\{closure}(*** sensitive parameters replaced ***)\\n#16 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/AppFramework\\\/Utility\\\/SimpleContainer.php(115): Pimple\\\\Container->offsetGet('RootFolder')\\n#17 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/ServerContainer.php(132): OC\\\\AppFramework\\\\Utility\\\\SimpleContainer->query('RootFolder')\\n#18 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Server.php(260): OC\\\\ServerContainer->query('RootFolder')\\n#19 [internal function]: OC\\\\Server->OC\\\\{closure}(*** sensitive parameters replaced ***)\\n#20 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Files\\\/Node\\\/LazyRoot.php(60): call_user_func(Object(Closure))\\n#21 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Files\\\/Node\\\/LazyRoot.php(140): OC\\\\Files\\\\Node\\\\LazyRoot->__call('get', Array)\\n#22 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Files\\\/AppData\\\/AppData.php(79): OC\\\\Files\\\\Node\\\\LazyRoot->get('appdata_ocbm3u1...')\\n#23 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Files\\\/AppData\\\/AppData.php(105): OC\\\\Files\\\\AppData\\\\AppData->getAppDataFolder()\\n#24 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Template\\\/JSCombiner.php(80): OC\\\\Files\\\\AppData\\\\AppData->getFolder('core')\\n#25 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Template\\\/JSResourceLocator.php(112): OC\\\\Template\\\\JSCombiner->process('\\\/home\\\/user...', 'core\\\/js\\\/merged-...', 'core')\\n#26 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Template\\\/JSResourceLocator.php(68): OC\\\\Template\\\\JSResourceLocator->cacheAndAppendCombineJsonIfExist('\\\/home\\\/user...', 'core\\\/js\\\/merged-...')\\n#27 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Template\\\/ResourceLocator.php(76): OC\\\\Template\\\\JSResourceLocator->doFind('js\\\/merged-templ...')\\n#28 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/TemplateLayout.php(304): OC\\\\Template\\\\ResourceLocator->find(Array)\\n#29 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/TemplateLayout.php(141): OC\\\\TemplateLayout::findJavascriptFiles(Array)\\n#30 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/legacy\\\/template.php(205): OC\\\\TemplateLayout->__construct('error', '')\\n#31 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Template\\\/Base.php(132): OC_Template->fetchPage()\\n#32 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/legacy\\\/template.php(309): OC\\\\Template\\\\Base->printPage()\\n#33 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/base.php(250): OC_Template::printErrorPage('Cannot write in...', 'This can usuall...')\\n#34 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/base.php(678): OC::checkConfig()\\n#35 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/base.php(1086): OC::init()\\n#36 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/console.php(42): require_once('\\\/home\\\/user...')\\n#37 \\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/occ(10): require_once('\\\/home\\\/user...')\\n#38 {main}\",\"File\":\"\\\/home\\\/user\\\/public_html\\\/dev\\\/nextcloud2\\\/lib\\\/private\\\/Files\\\/View.php\",\"Line\":1983}","userAgent":"--","version":"12.0.6.1"}
PHP Warning:  fileperms(): stat failed for /home/user/public_html/dev/nextcloud2/data/nextcloud.log in /home/user/public_html/dev/nextcloud2/lib/private/Log/File.php on line 133
{"reqId":"3xi4WbJhLZ1010N9qdbr","level":3,"time":"2018-04-17T17:45:59+00:00","remoteAddr":"","user":"--","app":"PHP","method":"--","url":"--","message":"Undefined index: SERVER_PROTOCOL at \/home\/user\/public_html\/dev\/nextcloud2\/lib\/private\/legacy\/template.php#368","userAgent":"--","version":"12.0.6.1"}
PHP Warning:  fileperms(): stat failed for /home/user/public_html/dev/nextcloud2/data/nextcloud.log in /home/user/public_html/dev/nextcloud2/lib/private/Log/File.php on line 133
{"reqId":"3xi4WbJhLZ1010N9qdbr","level":3,"time":"2018-04-17T17:45:59+00:00","remoteAddr":"","user":"--","app":"PHP","method":"--","url":"--","message":"fileperms(): stat failed for \/home\/user\/public_html\/dev\/nextcloud2\/data\/nextcloud.log at \/home\/user\/public_html\/dev\/nextcloud2\/lib\/private\/Log\/File.php#133","userAgent":"--","version":"12.0.6.1"}
{"reqId":"3xi4WbJhLZ1010N9qdbr","level":3,"time":"2018-04-17T17:45:59+00:00","remoteAddr":"","user":"--","app":"PHP","method":"--","url":"--","message":"chmod(): Permission denied at \/home\/user\/public_html\/dev\/nextcloud2\/lib\/private\/Log\/File.php#134","userAgent":"--","version":"12.0.6.1"}
Status: 500 Internal Server Error
Set-Cookie: ocbm3u12n9nd=j8io5nar804149n9t2acnan8v4; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: oc_sessionPassphrase=vOSk4OjpDPqfD2m116JmGKRQXIQ40HGK3jIpAkNE9UiaFM5C9o51LqpCfXLxyGijlsnPY9qhWwyWUcSTPOXWOuONmkSwISK1ZhnGzgeQ7IwSM5d75jSHuabwqzEOXJBP; path=/; HttpOnly
Content-Type: text/plain; charset=utf-8

Cannot write into "config" directory! This can usually be fixed by giving the webserver write access to the config directory. See https://docs.nextcloud.com/server/12/go.php?to=admin-dir_permissions

When I ran the command as a normal user without sudo it worked.

My Nextcloud install is working fine. What’s wrong with the occ command?