Where did I go wrong... again?

Iā€™m getting a ā€œ[Warning] Access denied for user ā€˜rootā€™@ā€˜localhostā€™ (using password: NO)ā€ message in the /var/log/mysql/error.log

Iā€™ve been fighting a LEARNING battle with NextCloud for a while now. Seems that Iā€™m getting further along every day though.

Had no guidance what users to make other than root (default) and an admin user; and was confused by which ā€œuserā€ to use when setting up NextCloud / mySQLā€™s nextcloud database.

I can successfully log into mySQL as either root or admin with the appropriate password, and the admin password (in clear-text) is correct in the nextcloud/config/config.php

Iā€™m just at a loss of where / how to fix the error that Iā€™m getting now.

Itā€™s causing me to be unable to access NextCloud at all. Give me a ā€œ404 Not Foundā€ page at *.org/index.php/login ā€“ well, itā€™s stopping me from going any further to find out what is giving me the error, if itā€™s not.

Just looking for a few suggestions of where to start looking. Thanks!

Using NGINX, MariaDB, PHP7.4, with SSL on Ubuntu 20.04 (no GUI)

I think you get normally not this error from your nextcloud because your nextcloud (config/config.php) users not the user ā€œrootā€ and uses a passoword (not: ā€œusing passowrd:NOā€).

I am at the exact same point!
I donā€™t know where I went wrong, especially since I am new to Linux/nextcloudā€¦
basically parroting the commands I am told to use in the installation guidesā€¦
One day, I hope Iā€™ll ā€œunderstandā€ what I am doing LOL
In the meantime, I hope G-Wiz and I find the answer :slight_smile:

It is important to understand what you are doing. So to help as I can I will try and explain for you.
Read along to the end as the beginning is already working for you.

Iā€™m old school so I use all the defaults where possible. Apache Web server has been there long before the made nginx and when I see some post from nginx I do not want to get into that. looks way too complicated compared to apache configs.

True I have never touched nginx so I could not judge it on there configs alone maybe there all suplied.

Anyways, There is a admin account on your linux system which is called ā€™ root ā€™ on newer linux systems this user is normally not able to login alone and you grant other users ā€™ sudo ā€™ power to use administrative rights. never the less the user root is still used to drive the system programs and logging.

The MariaDB is easy to setup and every time it is started it will check for insecure access. Hence you will always see

ā€œ[Warning] Access denied for user ā€˜rootā€™@ā€˜localhostā€™ (using password: NO)ā€

in your error.log That is why you need to share as much information about your system/logs when you want help here.

The user root in mariadb is the administrator and after you have secured your mariadb and created a account your pretty much done with that user.

setup mariadb and then create a user that can create a database for your nextcloud instance.
Here is how to setup MariaDB if newly installed and not used for anything other.

sudo apt install mariadb-server
sudo mysql_secure_installation

Answer all Yes with Y and set your root password
Now enter the database command line.

sudo mysql -u root -p 

this will open mysql with the user root asking for your password you made with mysql_secure_installation
This user is very powerfull and can destroy everything.
your command line should look like: mysql>

mysql command end with semi-colon ;
tell mysql to use the database mysql

use mysql;

now create a user for your nextcloud db so you do not have to enter the root account in your config.php

create user 'nc_dbuser'@'localhost' identified by 'YourP@s5w0rd';

The username for this account is nc_dbuser you can change it to what you want but for clearity this is the user to connect to the NextCloud DataBase

The localhost after @ tells mysql this user can only connect from the localhost which is your actual computer. no access from outside (WWW) allowed.
this is good for security.

Identified by obviously your own password here
Now we have a user we have to give it permissions what it may do.

grant all privileges on nextcloud.* to 'nc_dbuser'@'localhost';

This one could be better but will set it up no problems as access from outside is not allowed anyways.
grant all means all sql commands allowed now nextcloud.* means only allow it in database nextcloud and the .* means all tables inside nextcoud database.
the last part to again abviously the user to grant it to.

now I donā€™t know everything but you can use Google too

flush privileges;
quit;

your mariadb is now setup with a database named nextcloud this database can be accessed with username nc_dbuser and password: YourP@s5w0rd

this all seems to be already working fine for you.

Apache or NGINX

here is my apache command for setting up

apt install apache2 libapache2-mod-php libapache2-mod-php7.4 python3-certbot-apache certbot ssl-cert openssl php7.4 php-memcache php-imagick imagemagick  php-apcu php-redis php7.4-{bcmath,bz2,curl,gd,gmp,imap,intl,json,mbstring,mysql,opcache,pspell,readline,soap,tidy,xml,xmlrpc,zip}
sudo mkdir -p /var/www/nextcloud
sudo chown www-data:www-data /var/www/nextcloud/
cd /var/www/
sudo wget -O nc.tar.bz2 https://download.nextcloud.com/server/releases/nextcloud-19.0.2.tar.bz2
sudo -u www-data tar xjfp nc.tar.bz2
sudo a2ensite default-ssl.conf
sudo certbot run --apache -d cloud.usee.ga,www.usee.ga,usee.ga
sudo systemctl restart apache2
<VirtualHost *:80>
	Redirect permanent / https://cloud.usee.ga/
	ServerName usee.ga
	DocumentRoot /var/www/nextcloud
        ServerAlias www.usee.ga cloud.usee.ga
</VirtualHost>

<IfModule mod_ssl.c>
	<VirtualHost *:443>
		DocumentRoot /var/www/nextcloud
		ServerName usee.ga
                ServerAlias www.usee.ga cloud.usee.ga

		ErrorLog ${APACHE_LOG_DIR}/error.log
		CustomLog ${APACHE_LOG_DIR}/access.log combined

		<FilesMatch "\.(cgi|shtml|phtml|php)$">
				SSLOptions +StdEnvVars
		</FilesMatch>

		<Directory /usr/lib/cgi-bin>
				SSLOptions +StdEnvVars
		</Directory>

		<Directory /var/www/nextcloud>
				Options +FollowSymlinks
				AllowOverride All
                                SetEnv HOME /var/www/nextcloud
                                SetEnv HTTP_HOME /var/www/nextcloud

			<IfModule mod_dav.c>
			  Dav off
			</IfModule>
		</Directory>

                <IfModule mod_headers.c>
                          Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains"
                </IfModule>
            Include /etc/letsencrypt/options-ssl-apache.conf
            SSLCertificateFile /etc/letsencrypt/live/cloud.usee.ga/fullchain.pem
            SSLCertificateKeyFile /etc/letsencrypt/live/cloud.usee.ga/privkey.pem
</VirtualHost>
</IfModule>

Above is Apache site config
your NGINX may be pointing to /var/www/html/ or /var/www as webserver home I donā€™t know how you installed Nextcloud. some script or manually.
Maybe there are some missing modules please supply more info. no need to share sensitive information.

root user has nothing to do with nextcloud.

nc_dbuser is only to connect to your database. itā€™s login is stored in nextcloud/config/config.php

when browsing to your installation IP/DOMAIN you will create a new user for your nextcloud which will be the first user and will have admin rights for your nextcloud instance.

I hope this is of any help understanding users

Thank you for that thorough rundown! It helps confirm that my setup is looking okay so far.

When I finally got the NextCloud initial webpage to show up the other day for configuration. It asked me for a user name and I think thatā€™s where I messed up.

Having tried configuration from command line for so long I gave it ā€œrootā€ as the ā€œuserā€ and my admin as the ā€œadmin userā€. If that was not correct, is there any way to fix it?

Waitā€¦ no. My notes indicate that MySQL / NextCloud didnā€™t let me use root as the user.

Okay, back to the logs I go.

Thanks again for the informationā€¦ and that that error is normal.

Error is normal as long as itā€™s not duplicated

Things you can try

Create a file CAN_INSTALL in your nextcloud/config/ go-to your cloud domain and see if you can continue installation.

sudo -u www-data touch /var/www/nextcloud/config/CAN_INSTALL

If not delete the file no harm done.

sudo rm /var/www/nextcloud/config/CAN_INSTALL

You can retry with a new database and a fresh extraction of the nextcloud.zip

Or drop the existing database en recreate .

To drop a database

sudo mysql -u root -u

drop database nextcloud;

create database nextcloud;

quit;

As the user already exists no need to create it again.

NEVER GIVE UP.

Thanks for sticking with me on this.

That error was duplicatedā€¦ saw it in triplicate.

I was able to create the CAN_INSTALL file, but was not able to continue installation.

I quickly took your advice and stopped nginx, then mvā€™d the existing nextcloud directory to /nextcloud.old

I did a fresh extraction of nextcloud and set permissions for it.

I then dropped the old nextcloud database and created a new one.

I was able to get back to the setup page for NextCloudā€¦ butā€¦ now Iā€™ve got new problems.

ā€œMySQL username and/or password not valid You need to enter details of an existing account.ā€ error when clicking the Finish setup button. I know that the username and password work, as I can use them to log in from the command line (via mysql - not linux).

Also of note. I didnā€™t create any new users in mysqlā€¦ but I have my root and my ā€œUserAdminā€ and ā€œNextCloudUserā€ at ā€œlocalhostā€ā€¦ plus TWO EACH ā€œoc_UserAdmin1ā€ and ā€œoc_UserAdmin2ā€ accounts (one each at hosts ā€œ%ā€ and ā€œlocalhostā€).

three times at the same time right here is my sql log for reference

2020-08-31 23:59:28 139822234860672 [Note] Using unique option prefix 'myisam-recover' is error-prone and can break in the future. Please use the full name 'myisam-recover-options' instead.
2020-08-31 23:59:28 139822234860672 [Note] InnoDB: innodb_empty_free_list_algorithm has been changed to legacy because of small buffer pool size. In order to use backoff, increase buffer pool at least up to 20MB.

2020-08-31 23:59:28 139822234860672 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2020-08-31 23:59:28 139822234860672 [Note] InnoDB: The InnoDB memory heap is disabled
2020-08-31 23:59:28 139822234860672 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-08-31 23:59:28 139822234860672 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2020-08-31 23:59:28 139822234860672 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-08-31 23:59:28 139822234860672 [Note] InnoDB: Using Linux native AIO
2020-08-31 23:59:28 139822234860672 [Note] InnoDB: Using SSE crc32 instructions
2020-08-31 23:59:28 139822234860672 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-08-31 23:59:28 139822234860672 [Note] InnoDB: Completed initialization of buffer pool
2020-08-31 23:59:28 139822234860672 [Note] InnoDB: Highest supported file format is Barracuda.
2020-08-31 23:59:28 139822234860672 [Note] InnoDB: 128 rollback segment(s) are active.
2020-08-31 23:59:28 139822234860672 [Note] InnoDB: Waiting for purge to start
2020-08-31 23:59:28 139822234860672 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.46-86.2 started; log sequence number 62506039215
2020-08-31 23:59:28 139822234860672 [Note] Plugin 'FEEDBACK' is disabled.
2020-08-31 23:59:28 139821565605632 [Note] InnoDB: Dumping buffer pool(s) not yet started
2020-08-31 23:59:28 139822234860672 [Note] Server socket created on IP: '0.0.0.0'.
2020-08-31 23:59:29 139822234860672 [Note] Reading of all Master_info entries succeeded
2020-08-31 23:59:29 139822234860672 [Note] Added new Master_info '' to hash table
2020-08-31 23:59:29 139822234860672 [Note] /usr/sbin/mysqld: ready for connections.
Version: '10.1.44-MariaDB-0ubuntu0.18.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  Ubuntu 18.04
2020-08-31 23:59:29 139822234351360 [Warning] Access denied for user 'root'@'localhost' (using password: NO)
2020-08-31 23:59:29 139822234351360 [Warning]  Access denied for user 'root'@'localhost' (using password: NO)
2020-08-31 23:59:29 139822234351360 [Warning] Access denied for user 'root'@'localhost' (using password: NO)

sorry forgot flush privileges;

sudo mysql -u root -p -e "flush privileges;"

Okay, sorry about the silence the past few days - had to deal with real life family stuffā€¦ so now back to the NextCloud.

After a bit of thought, and seeing that the NextCloud Setup/Configuration page appeared to be trying to create a new user with every attemptā€¦ I realized how to position my ā€œUsersā€ and passwords that NextCloud was asking for.

I gave it a brand shiny new NextCloud Database Administrator User name and passcode for the ā€œAdmin Accountā€.
I then gave it the ā€œUser Nameā€ and passcode that I chose earlier when I setup MariaDB from the command line (while following the installation instructions) for the ā€œDatabase Userā€.

ā€¦ But, I still canā€™t get past the Initial Setup/Configuration page for NextCloud. Now it keeps giving me a ā€œCanā€™t create or write into the data directory opt/nextcloud/dataā€ Error message.

At least Iā€™m making progress.

The nextcloud/data/nextcloud.log gives me the following three messages:
ā€œCould not detect any host in http:///data/htaccesstest.txtā€
ā€œmkdir(): No such file or directory at /var/www/html/nextcloud/lib/private/Setup.php#312ā€
ā€œCould not find resource js/setup.js to loadā€

Iā€™ve checked the php.ini file for ā€œopen_basedir = noneā€. It wasnā€™t there, I added it. It made no difference.
Iā€™ve checked my mySQL nextcloud database oc_storages table for correctly pointing at /opt/nextcloud/data
/opt/nextcloud and /opt/nextcloud/data belong to www-data user and group with 755 permissions (777 permissions made no differenceā€¦ and 755 permissions mirror the default NextCloud install).

Any suggestions where to look next?

Since this now seems to be a different error / issue, I think I will stop this thread here, and post the previous post as another thread.