Problem with Nextcloud

Hello everyone,

I’m getting into Nextcloud for the first time and have installed it on my server with an Ubuntu VM. I followed these instructions (see commands below).

I did the following differently than described in the instructions:

  1. I entered my IP address for the server name. I only use it locally.
  2. My data is located under /mnt/nextcloud and not under /var.

Everything worked and I was able to use Nextcloud. However, after restarting the VM machine, I get the following error message (see unter) and therefore cannot use Nextcloud.

The data directory is invalid
Please ensure that a “.ncdata” file exists in the root directory of the data directory. It should have the following content: “# Nextcloud data directory”
The data directory is write-protected.
Permissions can usually be corrected by granting the web server write access to the root directory. See also Introduction — Nextcloud latest Administration Manual latest documentation

What do I have to do or which commands do I have to execute to get information that will help you?

Commands:
updating
apt update && apt upgrade -y

Installing apache
apt install apache2 -y

Install PHP 8.3
apt install software-properties-common
add-apt-repository ppa:ondrej/php
apt update

Install PHP 8.3 & Moduls
apt install php8.3 libapache2-mod-php8.3 php8.3-zip php8.3-xml php8.3-mbstring php8.3-gd php8.3-curl php8.3-imagick libmagickcore-6.q16-6-extra php8.3-intl php8.3-bcmath php8.3-gmp php8.3-cli php8.3-mysql php8.3-zip php8.3-gd php8.3-mbstring php8.3-curl php8.3-xml php-pear unzip nano php8.3-apcu redis-server ufw php8.3-redis php8.3-smbclient php8.3-ldap php8.3-bz2 php8.3-sqlite3

adjust PHP.ini file
nano /etc/php/8.3/apache2/php.ini
memory_limit = 4096M
upload_max_filesize = 20G
post_max_size = 20G
date.timezone = Europe/Berlin
output_buffering = Off
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1

Install Databse Server
apt install mariadb-server

Maria DB Server Konfiguration
mysql_secure_installation

open SQL dialoge
mysql

create database calles nextcloud
CREATE DATABASE nextcloud;

create database user with password
CREATE USER ‘nextclouduser’@‘localhost’ IDENTIFIED BY ‘password_here’;
#grant accesss to databse
GRANT ALL PRIVILEGES ON nextcloud.* TO ‘nextclouduser’@‘localhost’;
#save changes and exit
FLUSH PRIVILEGES;
EXIT;

Download lastest nextcloud version
cd /tmp && wget https://download.nextcloud.com/server/releases/latest.zip
unzip latest.zip
mv nextcloud /var/www/

#create new conf

nano /etc/apache2/sites-available/nextcloud.conf
<VirtualHost *:80>
ServerAdmin master@domain.com
DocumentRoot /var/www/nextcloud/
ServerName
<Directory /var/www/nextcloud/>
Options +FollowSymlinks
AllowOverride All
Require all granted

Dav off

SetEnv HOME /var/www/nextcloud
SetEnv HTTP_HOME /var/www/nextcloud

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

Enable the NextCloud and Rewrite Module
a2ensite nextcloud.conf

a2enmod rewrite
a2enmod headers
a2enmod env
a2enmod dir
a2enmod mime

restart apache
service apache2 restart

prepare data folder
mkdir /home/data/

chown -R www-data:www-data /home/data/
chown -R www-data:www-data /var/www/nextcloud/
chmod -R 755 /var/www/nextcloud/

Best regards
Berto

1 Like

change owner and user of /mnt/nextcloud make sure that you have the .ncdata file in that directory.

Could you write the commands to check if I have the .ncdata file in that directory, and explain how to change the owner and user of /mnt/nextcloud?

Could you also write the commands?

chown -R www-data:www-data /mnt/nextcloud

ls -l /mnt/nextcloud/.ncdata

If .ncdata is missing

touch /mnt/nextcloud/.ncdata

Your error happens because Nextcloud needs a .ncdata file in your data directory and proper permissions. To fix:

Create the .ncdata file inside /mnt/nextcloud with this content:

Nextcloud data directory

Set ownership and permissions:

sudo chown -R www-data:www-data /mnt/nextcloud
sudo chmod -R 750 /mnt/nextcloud

Ensure your Nextcloud config (config.php) points to /mnt/nextcloud as the data directory.

Then restart Apache (sudo systemctl restart apache2). This should resolve the issue.