Hello,
I’m trying to initialize NextCloud, but NC can’t seem to connect to the MySQL DB.
I get this error on the initialization page:
Error while trying to create admin user: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory
I’ve tried to re-install NC via the CLI with nextcloud_install, following the instructions to delete the config.php file, drop the nextcloud DB, and drop the nextcloud@localhost and nextcloud@127.0.0.1 users.
There is also /srv/mysql that has to has correct owner - mysql:mysql. I think we might be running webserver as nobody - try that one for the Nextcloud directory.
This solution also doesn’t seem to resolve my particular issue.
As a side note, I can connect to MySQL via mysql -u root, so the service is running.
Another important detail: I had previously installed NC on my device, and it worked perfectly fine. However, I made the mistake of installing NC it before initializing my external storage. I then rolled my device back to an earlier snapshot so I could set up my external storage and install NC in the proper order. It was after this that I began experiencing this issue.
Any help on this issue would be greatly appreciated!
Additional info:
Device: Omnia TurrisOS version:6.2.3 NextCloud Data folder location:/srv/www/nextcloud/data. MariaDB server version:10.4.26
Using 127.0.0.1 as my DB host (instead of localhost) in the NC installation wizard seems to get me closer to a solution. This was discovered on this StackOverflow answer.
Additionally, I discovered I needed to append the correct port to the host address, e.g. 127.0.0.1:3306.
I created a nextcloud database in MySQL.
CREATE DATABASE nextcloud;
I then created a new DB user and granted the user access to the DB.
CREATE USER '<user>'@'127.0.0.1' IDENTIFIED BY '<password>';
GRANT ALL ON nextcloud.* TO '<user>'@'127.0.0.1';
Even after running the query, though, I get this error in the NC initialization wizard:
MySQL username and/or password not valid You need to enter details of an existing account.
After modifying the /srv/www/nextcloud/lib/private/Setup/MySQL.php file to var_dump() the exception object, I can see this error is occurring behind the scenes:
Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [1045] Access denied for user ‘<user>’@‘localhost’ (using password: YES)"
Note, <user> is the same DB user account that I had already created for NC.
Eventually, I just decided to try to manually install the latest version of NextCloud (v25). While it doesn’t seem to be officially supported by the Omnia, as far as I can tell, installing it was simple and it seems to work just fine.
First, I manually removed the existing nextcloud/ directory.
cd /srv/www/;
rm -rf nextcloud/;
Then I dropped my existing DB.
DROP DATABASE nextcloud;
I downloaded the nextcloud archive and extracted it.
wget https://download.nextcloud.com/server/releases/nextcloud-25.0.3.tar.bz2;
tar -xvf ./nextcloud-25.0.3.tar.bz2;
Finally, I ran the installation wizard in the browser. It worked perfectly time. Note, I did have to follow the instructions from above regarding the database configuration.
One drawback
After I installed NC 25 and confirmed that it worked properly, I tried to uninstall the exiting nextcloud v23 package from LuCi. I didn’t want two versions of NC wasting space on my device.
Unfortunately, removing NC 23 broke my NC 25 installation. I fixed it by simply rolling back to a previous snapshot, ensuring the NC 23 package was installed, and repeated the NC 25 manual installation steps. I’m going to leave v23 as it is for now. I’m sure it’s a simple fix to remove v23 and get v25 running again. It’s probably that removal of the v23 package also eliminates a dependency upon which v25 relies.