How to Install and Configure the Nextcloud File Sync Platform on Debian

Your Own Private Cloud Storage

Cloud storage services like Google Drive or Dropbox are incredibly convenient, but trusting third-party corporations with your sensitive company data—and paying expensive recurring subscription fees per user—is often unacceptable. Nextcloud is a fully open-source, self-hosted file synchronization platform. It provides the exact same seamless experience as Dropbox, complete with desktop sync clients and mobile apps, but the data lives 100% on your own Debian server and your own hard drives.

Step 1: Install the LAMP Stack

Nextcloud is a PHP-based web application that requires a database. Install Apache, MariaDB, and all necessary PHP extensions:

sudo apt update

sudo apt install apache2 mariadb-server libapache2-mod-php php-gd php-mysql php-curl php-mbstring php-intl php-gmp php-bcmath php-xml php-imagick php-zip unzip wget -y

Step 2: Secure the Database and Create a User

Run the MariaDB security script to set a root password (sudo mysql_secure_installation). Then, log into the database to create a dedicated user for Nextcloud:

sudo mysql -u root -p

Execute the following SQL commands:


CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 3: Download and Extract Nextcloud

Download the latest Nextcloud archive to your web root and extract it:

cd /var/www/html/

sudo wget https://download.nextcloud.com/server/releases/latest.zip

sudo unzip latest.zip

The web server user (www-data) must have full read and write permissions to the Nextcloud directory, as it will need to save uploaded files and update its own configuration.

sudo chown -R www-data:www-data /var/www/html/nextcloud/

sudo chmod -R 755 /var/www/html/nextcloud/

Step 4: Configure Apache Virtual Host

Create a dedicated Apache configuration file for Nextcloud to ensure proper routing and allow URL rewrites.

sudo nano /etc/apache2/sites-available/nextcloud.conf

Add the following configuration:


<VirtualHost *:80>
DocumentRoot /var/www/html/nextcloud/
ServerName cloud.yourdomain.com

<Directory /var/www/html/nextcloud/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
</Directory>
</VirtualHost>

Enable the site, enable the required Apache modules, and restart the web server:

sudo a2ensite nextcloud.conf

sudo a2enmod rewrite headers env dir mime

sudo systemctl restart apache2

Step 5: Complete the Web Installation

Open your web browser and navigate to your server’s IP address or domain name (e.g., http://cloud.yourdomain.com). You will be greeted by the Nextcloud initial setup wizard.

Create an admin username and password. In the database section, select MariaDB/MySQL and input the database name (nextcloud), username (nextclouduser), and the password you created in Step 2.

Click Install. Nextcloud will initialize the database and load into your new private cloud dashboard. From here, you can create users, share files via public links, and download the desktop sync clients to connect your PCs directly to your private server.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.