[NCP] Internal Server Error

Hi, after an apt upgrade I get this message:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

Here you have the ncp-report output.

Thanks for your help!

Taking a look to /var/log/mysql/error.log I get:

2021-10-07 11:26:29 0 [ERROR] InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace.
2021-10-07 11:26:29 0 [ERROR] InnoDB: Plugin initialization aborted with error Tablespace not found
2021-10-07 11:26:29 0 [Note] InnoDB: Starting shutdown...
2021-10-07 11:26:30 0 [ERROR] Plugin 'InnoDB' init function returned error.
2021-10-07 11:26:30 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2021-10-07 11:26:30 0 [Note] Plugin 'FEEDBACK' is disabled.
2021-10-07 11:26:30 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
2021-10-07 11:26:30 0 [ERROR] Unknown/unsupported storage engine: InnoDB
2021-10-07 11:26:30 0 [ERROR] Aborting

Following instruction and setting innodb_force_recovery=1 the error is now this one:

2021-10-07 11:39:58 4 [ERROR] InnoDB: Cannot open datafile for read-only: './nextcloud/oc_jobs.ibd' OS error: 81
2021-10-07 11:39:58 4 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2021-10-07 11:39:58 4 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2021-10-07 11:39:58 4 [ERROR] InnoDB: Could not find a valid tablespace file for ``nextcloud`.`oc_jobs``. Please refer to https://mariadb.com/kb/en/innodb-data-dictionary-troubleshooting/ for how to resolve the issue.
2021-10-07 11:39:58 0 [Note] Starting crash recovery...
2021-10-07 11:39:58 0 [Note] Crash recovery finished.
2021-10-07 11:39:58 0 [Note] InnoDB: Buffer pool(s) load completed at 211007 11:39:58
2021-10-07 11:39:58 0 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
2021-10-07 11:39:58 0 [Note] Server socket created on IP: ''.
2021-10-07 11:39:58 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

I did a look through your ncp-report log and this is the error that is telling you what the issue is, as far as I can tell.

Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory in /var/www/nextcloud/lib/private/DB/Connection.php:85

According to some good folks over at Stackoverflow this is an error code indicating the databse connection is using an unsupported socket, however there are also some threads here in this forum where people have had the same issue and it has been due to a PHP version mismatch and one because the apache server started before the database connection was established, I’ll put the links below to where I found this information :slight_smile:

Stackoverflow 1
Stackoverflow 2
Stackoverflow 3
Stackoverflow 4

And here is from the MySQL troubleshooting guide regarding the error code [2002] (which you are getting) both in the 5.6 version and the MySQL 8 version.
MySQL Troubleshooting 5.6
Here it is stating the same thing in the MySQL v.8 Troubleshooting documentation
MySQL Troubleshooting v.8

The error (2002) Can't connect to ... normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.

The other Nextcloud forum posts about this issue
Failed to connect to NC
Failed to connect to the database
Closed GitHub issue: Failed to connect to the database

SInce you said it occured for you after an upgrade I’d recommend starting there and checking so your PHP version all match and none of them are out of sync

I hope this helps you in the right direction to the solution and to #resolve it :slight_smile:

Found this is in the Nextcloud admin docs just now while looking at another issue.
Nextcloud Admin Docs

  • SQLSTATE[HY000] [2002] No such file or directory → There is a problem accessing your SQLite database file in your data directory (data/nextcloud.db). Please check the permissions of this folder/file or if it exists at all. If you’re using MySQL please start your database.

I just decided to reinstall everything.

During the installation, I get this error message:
ERROR 1006 (HY000) at line 2: Can't create database 'nextcloud' (errno: 2 "No such file or directory")

And this error message when I try to connect to Nextcloud:
Forbidden You don't have permission to access this resource.

ncp-report: https://bin.snopyta.org/?1843ab044aac23b0#89vvfe7Wi2FrgzhYf5rrn6bp5hcFjB4k6UWWrVm88oku

How are you performing your installation and what kind of setup are you using?

Looks like no database directory has been created?

How are you trying to connect to Nextcloud?

Performing the installation with ncp-config on a Raspberry Pi 4. Trying to connect to Nextcloud with https?

Well it looks like you haven’t created the ncdata, ncdatabase, ncbackup directories and set the correct permissions?

Shouldn’t the installation create them itself? How do I fix the problem properly now? Thanks for helping me.

No worries, we’re all community members here, so we try and help each other as much we can :blush:

Indeed yes it should, as far as I’m aware anyway unless you’re using external drives or USB drives with your installation. Though I installed it externally and had to create these directories myself

Which is why I asked for more information about your installation process, to see which steps you’re using and if there’s something missed there.

Do you only use an SD card for the installation? No external drives?

What pc did you use for flashing the card? (mac, windows, linux)

What software did you use for the flashing?

After flashing the card and booting it up, which steps did you take?

Please be as precise and detailed as you can while also being mindful of not posting any personal info such as, domain, IP, password or passwordsalt etc

Sorry I’m doing a lot of things simultaneously today so I might be slow

Do you only use an SD card for the installation? No external drives? → ncdata and ncdatabase should be on /media/USBdrive as I use and external HDD

What pc did you use for flashing the card? (mac, windows, linux) → linux

What software did you use for the flashing? → Raspberry Pi Imager

After flashing the card and booting it up, which steps did you take? → just a classic apt update && apt upgrade

Alright, so you did create the folders on the external drive? :slight_smile:
It sounds like you haven’t finished the installation fully, since you’re using an external drive you need to manually move the data directory and database inside nextcloud after activating it.

Regarding connecting through https, you can’t connect to your Nextcloud instance with https before you’ve gotten yourself an certificate either from Letsencrypt or a self-signed one.
I also recommend finishing setting up the nextcloud instance so you have a working data directory and database before you perform any apt update && apt upgrade for the device

After you’ve finished the installation and activated NCP at nextcloudpi.local, getting your generated passwords for the default users, you should be prompted to go through the first installation wizard and it should ask you if you are using a USB drive and if you wish to move the datadir, what happens when you run through this wizard?

It should run nc-datadir with the path to your /ncdata folder with the default path: /media/USBdrive/ncdata

Also just to make sure, are you intending on having the /root system files remaining on your SD card or move it to the external USB drive?
If you intend to move it this should be done pre-installation, you can use the guide below to do it

Pragmatic Linux - Move the Raspberry Pi /root file system to a USB drive