Nextcloud 21 appears to still be running as http user

Nextcloud version (eg, 20.0.5): 21.0.0.18
Operating system and version (eg, Ubuntu 20.04): Arch Linux (updated)
Apache or nginx version (eg, Apache 2.4.25): 2.4.46-3
PHP version (eg, 7.4): 8.0.3

The issue you are facing:

Nextcloud 21 appears to still be running as the http user, despite the upgrade to nextcloud 21. The error I was originally getting was that nextcloud couldn’t open the config file (and was displaying an internal server error page), when the permissions were:

total 68                                                                                                                                               
-rw-r--r-- 1 nextcloud nextcloud     0 Mar  3 11:33 CAN_INSTALL                                                                                        
-rw-r----- 1 nextcloud nextcloud  1281 Mar 22 17:48 config.php                                                                                         
-rw-r----- 1 nextcloud nextcloud   345 Mar  3 11:33 config.php.pacnew                                                                                  
-rw-r--r-- 1 nextcloud nextcloud 59087 Mar  3 11:33 config.sample.php   

Then, when the permissions were changed to:

total 68
-rw-r--r-- 1 http http     0 Mar  3 11:33 CAN_INSTALL
-rw-r----- 1 http http  1281 Mar 22 17:48 config.php
-rw-r----- 1 http http   345 Mar  3 11:33 config.php.pacnew
-rw-r--r-- 1 http http 59087 Mar  3 11:33 config.sample.php

The error then became (when navigating to the root web directory in a browser):



    Your data directory is invalid

    Ensure there is a file called ".ocdata" in the root of the data directory.

    Cannot write into "apps" directory

    This can usually be fixed by giving the webserver write access to the apps directory or disabling the appstore in the config file.

    Your data directory is not writable

    Permissions can usually be fixed by giving the webserver write access to the root directory. See https://docs.nextcloud.com/server/21/go.php?to=admin-dir_permissions.

I should note that the data, and apps directories are owned by the nextcloud user.

The output of your Nextcloud log in Admin > Logging:

{
   "reqId":"S1N3rid9GyF1aMMaVz9t",
   "level":3,
   "time":"2021-03-23T14:40:52+00:00",
   "remoteAddr":"192.168.1.1",
   "user":"--",
   "app":"PHP",
   "method":"GET",
   "url":"/",
   "message":{
      "Exception":"Error",
      "Message":"touch(): Utime failed: Permission denied at /usr/share/webapps/nextcloud/lib/private/Config.php#247",
      "Code":0,
      "Trace":[
         {
            "function":"onError",
            "class":"OC\\Log\\ErrorHandler",
            "type":"::"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/private/Config.php",
            "line":247,
            "function":"touch"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/private/Config.php",
            "line":137,
            "function":"writeData",
            "class":"OC\\Config",
            "type":"->"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/private/SystemConfig.php",
            "line":111,
            "function":"setValue",
            "class":"OC\\Config",
            "type":"->"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/private/legacy/OC_Util.php",
            "line":1173,
            "function":"setValue",
            "class":"OC\\SystemConfig",
            "type":"->"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/base.php",
            "line":413,
            "function":"getInstanceId",
            "class":"OC_Util",
            "type":"::"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/base.php",
            "line":639,
            "function":"initSession",
            "class":"OC",
            "type":"::"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/base.php",
            "line":1076,
            "function":"init",
            "class":"OC",
            "type":"::"
         },
         {
            "file":"/usr/share/webapps/nextcloud/index.php",
            "line":35,
            "args":[
               "/usr/share/webapps/nextcloud/lib/base.php"
            ],
            "function":"require_once"
         }
      ],
      "File":"/usr/share/webapps/nextcloud/lib/private/Log/ErrorHandler.php",
      "Line":92,
      "CustomMessage":"--"
   },
   "userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0",
   "version":""
}

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 => '192.168.1.32',        
    1 => '***.com',
  ),                                                                       
  'apps_paths' => 
  array (                        
    0 => 
    array (                     
      'path' => '/usr/share/webapps/nextcloud/apps',
      'url' => '/apps',     
      'writable' => false,  
    ),  
    0 => 
    array (
      'path' => '/usr/share/webapps/nextcloud/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/lib/nextcloud/apps',
      'url' => '/wapps',
      'writable' => true,
    ),
  ),
  'datadirectory' => '/srv/nextcloud',
  'dbtype' => 'mysql',
  'version' => '21.0.0.18',
  'overwrite.cli.url' => 'http://192.168.1.32/',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '***',
  'installed' => true,
  'loglevel' => 1,
  'log_type' => 'file',
  'logfile' => '/var/log/nextcloud/nextcloud.log',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'maintenance' => false,
  'mail_smtpmode' => 'sendmail',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => 'root',
  'mail_domain' => '***.com',
  'theme' => '',
  'default_phone_region' => 'US',
);

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

{
   "reqId":"S1N3rid9GyF1aMMaVz9t",
   "level":3,
   "time":"2021-03-23T14:40:52+00:00",
   "remoteAddr":"192.168.1.1",
   "user":"--",
   "app":"PHP",
   "method":"GET",
   "url":"/",
   "message":{
      "Exception":"Error",
      "Message":"touch(): Utime failed: Permission denied at /usr/share/webapps/nextcloud/lib/private/Config.php#247",
      "Code":0,
      "Trace":[
         {
            "function":"onError",
            "class":"OC\\Log\\ErrorHandler",
            "type":"::"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/private/Config.php",
            "line":247,
            "function":"touch"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/private/Config.php",
            "line":137,
            "function":"writeData",
            "class":"OC\\Config",
            "type":"->"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/private/SystemConfig.php",
            "line":111,
            "function":"setValue",
            "class":"OC\\Config",
            "type":"->"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/private/legacy/OC_Util.php",
            "line":1173,
            "function":"setValue",
            "class":"OC\\SystemConfig",
            "type":"->"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/base.php",
            "line":413,
            "function":"getInstanceId",
            "class":"OC_Util",
            "type":"::"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/base.php",
            "line":639,
            "function":"initSession",
            "class":"OC",
            "type":"::"
         },
         {
            "file":"/usr/share/webapps/nextcloud/lib/base.php",
            "line":1076,
            "function":"init",
            "class":"OC",
            "type":"::"
         },
         {
            "file":"/usr/share/webapps/nextcloud/index.php",
            "line":35,
            "args":[
               "/usr/share/webapps/nextcloud/lib/base.php"
            ],
            "function":"require_once"
         }
      ],
      "File":"/usr/share/webapps/nextcloud/lib/private/Log/ErrorHandler.php",
      "Line":92,
      "CustomMessage":"--"
   },
   "userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0",
   "version":""
}

I can only think of these errors as occuring if nextcloud is running as the http user for some reason? Is there something I missed in the upgrade?

I think I had the same problem, and I think I just solved it.

My php-fpm configuration file (/etc/php/php-fpm.d/nextcloud.conf) looks like

[nextcloud]
user = nextcloud
group = nextcloud

When I then changed the user and group of /etc/php/php-fpm.d/www.conf to

[www]
user = nextcloud
group = nextcloud

it worked.