Login loop after fresh install

Hello everyone,

just like the title says, after I’ve installed the nextcloud i have issues of login loop. I enter my credentials and immediately returns me back to login page, doesn’t seem to log me in. It does however try to redirect me to /index.php/apps/dashboard/ (it appends redirect_url=/index.php/apps/dashboard/ to current URL). That’s a brief summary, bellow are more information.

OS: CentOS 8.2.2004
Web Server: Apache 2.4
PHP Version: 7.4 via php-fpm
Nextcloud Version: 20.0.2
Web Root Path: /mnt/2TB/www/nextcloud

Apache Virtual Host Configuration:

<VirtualHost *:443>
    DocumentRoot "/mnt/2TB/www/nextcloud"
    ServerName nc.domain.rs

    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateKeyFile /etc/letsencrypt/live/domain.rs/privkey.pem
    SSLCertificateFile /etc/letsencrypt/live/domain.rs/fullchain.pem

    Include /etc/httpd/php74-php.conf
    <Directory "/mnt/2TB/www/nextcloud">
        Options FollowSymLinks MultiViews
        AllowOverride All
        <IfModule mod_dav.c>
            Dav Off
        </IfModule>
        Require all granted
    </Directory>

    DirectoryIndex index.php index.html

    LogLevel warn
    ErrorLog /var/log/httpd/nc.domain.rs.error.log
    CustomLog /var/log/httpd/nc.domain.rs.access.log combined

</VirtualHost>

NextCloud Config:

<?php
$CONFIG = array (
  'passwordsalt' => 'EP2q+edited',
  'secret' => 'edited+waEu4ZtMK5FfBZUm',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => 'nc.domain.rs',
  ),
  'datadirectory' => '/mnt/2TB/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '20.0.2.2',
  'overwrite.cli.url' => 'https://nc.domain.rs',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nc',
  'dbpassword' => 'edited',
  'installed' => true,
  'instanceid' => 'edited',
  'maintenance' => false,
);

Output of nextcloud.log

{"reqId":"X8dZcyDVr6Jq12K7HcvviQAAAEc","level":3,"time":"2020-12-02T09:08:04+00:00","remoteAddr":"192.168.0.3","user":"--","app":"index","method":"GET","url":"/index.php/apps/theming/icon?v=0","message":{"Exception":"OCP\\Files\\NotPermittedException","Message":"Could not create folder","Code":0,"Trace":[{"file":"/mnt/2TB/www/nextcloud/lib/private/Files/AppData/AppData.php","line":157,"function":"newFolder","class":"OC\\Files\\Node\\Folder","type":"->","args":["0"]},{"file":"/mnt/2TB/www/nextcloud/apps/theming/lib/ImageManager.php","line":155,"function":"newFolder","class":"OC\\Files\\AppData\\AppData","type":"->","args":["0"]},{"file":"/mnt/2TB/www/nextcloud/apps/theming/lib/ImageManager.php","line":170,"function":"getCacheFolder","class":"OCA\\Theming\\ImageManager","type":"->","args":[]},{"file":"/mnt/2TB/www/nextcloud/apps/theming/lib/Controller/IconController.php","line":164,"function":"getCachedImage","class":"OCA\\Theming\\ImageManager","type":"->","args":["touchIcon-core"]},{"file":"/mnt/2TB/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":169,"function":"getTouchIcon","class":"OCA\\Theming\\Controller\\IconController","type":"->","args":["core"]},{"file":"/mnt/2TB/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":100,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\Theming\\Controller\\IconController"},"getTouchIcon"]},{"file":"/mnt/2TB/www/nextcloud/lib/private/AppFramework/App.php","line":152,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\Theming\\Controller\\IconController"},"getTouchIcon"]},{"file":"/mnt/2TB/www/nextcloud/lib/private/Route/Router.php","line":308,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\Theming\\Controller\\IconController","getTouchIcon",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"app":"core","action":null,"_route":"theming.Icon.getTouchIcon"}]},{"file":"/mnt/2TB/www/nextcloud/lib/base.php","line":1008,"function":"match","class":"OC\\Route\\Router","type":"->","args":["/apps/theming/icon"]},{"file":"/mnt/2TB/www/nextcloud/index.php","line":37,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"/mnt/2TB/www/nextcloud/lib/private/Files/Node/Folder.php","Line":167,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0","version":"20.0.2.2"}

Output of Web Server error log

[Wed Dec 02 09:37:33.729700 2020] [proxy_fcgi:error] [pid 317996:tid 139730830214912] (70007)The timeout specified has expired: [client 192.168.0.3:43580] AH01075: Error dispatching request to : (polling)
[Wed Dec 02 09:45:20.466898 2020] [proxy_fcgi:error] [pid 319886:tid 140018676918016] (70007)The timeout specified has expired: [client 192.168.0.3:43732] AH01075: Error dispatching request to : (polling)
[Wed Dec 02 09:45:21.497833 2020] [access_compat:error] [pid 319672:tid 140019817735936] [client 192.168.0.200:41290] AH01797: client denied by server configuration: /mnt/2TB/www/nextcloud/data/htaccesstest.txt
[Wed Dec 02 09:45:21.746655 2020] [access_compat:error] [pid 319672:tid 140019800950528] [client 192.168.0.200:41294] AH01797: client denied by server configuration: /mnt/2TB/www/nextcloud/data/htaccesstest.txt
[Wed Dec 02 09:45:41.684791 2020] [access_compat:error] [pid 319886:tid 140019197003520] [client 192.168.0.200:41300] AH01797: client denied by server configuration: /mnt/2TB/www/nextcloud/data/htaccesstest.txt
[Wed Dec 02 09:45:41.796115 2020] [access_compat:error] [pid 319886:tid 140019180218112] [client 192.168.0.200:41304] AH01797: client denied by server configuration: /mnt/2TB/www/nextcloud/data/htaccesstest.txt

Installation methods i have tried:

  • Created MySQL User and assigned privileges (did not create database, i have let nc create database).
  • Copied nextcloud files to web root.
  • Created ~/data dir, chown-ed all to apache:apache
  • Opened URL and configured mysql and admin user and password.
    ~ Installation timed out !!! I managed to see database created and tables populated, config.php also created.

Second time i removed data folder and database and performed installation from cli.

sudo -u apache php74 occ maintenance:install --database \
"mysql" --database-name "nextcloud"  --database-user "nc" --database-pass \
"redacted" --admin-user "redacted" --admin-pass "redacted"

Installation completed successfully however, login loop occurs.
Web root dir is a bit different as i have that on a 4TB RAID5 drive consisted of 2TB drives so i want my data properly secure of data loss and/or hardware failure, so only thing i can think of is not having the NC in proper web dir but i have all permissions needed set in apache virtual host file. I have another instance of nextcloud installed on a public server and works perfectly, setup is identical to this one.

PHP modules list:

[root@controller php74-php-fpm]# php74 -m
[PHP Modules]
apcu
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
igbinary
imagick
imap
intl
json
libsmbclient
libxml
mbstring
msgpack
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
phpiredis
posix
readline
redis
Reflection
session
shmop
SimpleXML
smbclient
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib

[Zend Modules]

I would appreciate help troubleshooting this one.
Regards!

EDIT:
Just moved the folder from /mnt/2TB/www/nextcloud to /var/www/html and i managed to access it. So any help on why doesn’t work with above apache directive and another mount dir ?
EDIT2:
It doesn’t actually have anything to do with the path but with the subdomain. I originally intended nextcloud to be at nc.domain.rs, when i moved www data to /var/www/html there was hosted under domain.rs and it works. Apache config for both of them are identical… Now I’m stumped…

SELinux enabled?

SELinux is disabled, just updated the main post as we speak, it doesn’t have anything to do with folder, as it seems.

… found it… though i don’t know why it wasn’t logged by nextcloud (there , a feature request!)…

Bear with me.

Reason for this worked is that main domain wasn’t set to work with php 7.4, instead it used 7.2 (default with centos) so i forgot about that. When i switched it to 7.4 same issue occured.

I had another app on main domain which also used php and that app logged an error when i tried to access it that it was unable to write to /var/lib/php/sessions. Default php 7.2 was logging sessions in /var/lib/php/session (singular), and sessions dir was non existent.

Resolution:
I created /var/lib/php/sessions and adjusted proper permissions (group apache and 770 access) and NC worked.

Going back to work! Stay safe everyone!

1 Like

To anybody who is running into this issue using CentOS 7 with PHP 8.0: maybe this helps (just got it working after a 7 hour debugging session):

My problem was not Nextcloud, but CentOS itself. Similarly to @maretodoric the issue is with PHP-sessions: PHP-FPM can not access the directory by default, if it is run using the nginx user and group (which is necessary using NGINX currently). And since the user nginx is not added to the apache group by default, PHP-sessions break.

Try

sudo chown -R nginx:nginx /var/lib/php

and make sure PHP-FPM uses the nginx user / group. I could not read any log entry in NGINX, Nextcloud or PHP-FPM about this. Very weird indeed.

Also make sure, that Nextcloud has the correct permissions set. Using the zip-file and unzip, wrong permissions were applied by default and 770 nginx:nginx does not suffice. Use the tarball instead and chown it afterwards (just to make sure this is not the issue).

Problem is related to Cookies, I had the same problem. Clearing the Browser cache doesn’t always remove the Cookies this is the case with Brave Browser.