Nextcloud is a powerful open-source platform that allows you to host your own secure and private cloud server. With Nextcloud, you can store, share, and access your data from anywhere — all while maintaining complete control. If you’re using a Debian-based distribution like Ubuntu or Debian itself, installing Nextcloud is straightforward. This guide will walk you through each step to get Nextcloud up and running on your server.
Prerequisites
Table of Contents
Before you begin, make sure you have the following:
- A server running Ubuntu 20.04+ or Debian 10+
- Root or
sudo
access - A fully qualified domain name (FQDN) pointed to your server’s IP
- Basic familiarity with the Linux terminal
Step 1: Update Your System
Start by updating your system packages for compatibility and security:
sudo apt update && sudo apt upgrade -y
Step 2: Install Apache, MariaDB, and PHP
Nextcloud requires a LAMP stack (Linux, Apache, MySQL or MariaDB, PHP). To install these:
sudo apt install apache2 mariadb-server libapache2-mod-php php php-mysql php-gd php-xml php-curl php-zip php-mbstring php-intl php-bcmath php-imagick php-gmp -y
Enable Apache and MariaDB to start on boot:
sudo systemctl enable apache2
sudo systemctl enable mariadb
Step 3: Configure MariaDB
Next, secure your database and create a database for Nextcloud:
sudo mysql_secure_installation
Then log into the MariaDB shell:
sudo mysql -u root -p
Run the following SQL commands to create the database and user:
CREATE DATABASE nextcloud;
CREATE USER 'ncuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'ncuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 4: Download and Extract Nextcloud
Download the latest version of Nextcloud from their official site:
wget https://download.nextcloud.com/server/releases/latest.zip
unzip latest.zip
sudo mv nextcloud /var/www/
Set the correct permissions:
sudo chown -R www-data:www-data /var/www/nextcloud
sudo chmod -R 755 /var/www/nextcloud
Step 5: Configure Apache
Create a new configuration file for Nextcloud:
sudo nano /etc/apache2/sites-available/nextcloud.conf
Paste the following configuration, replacing your_domain.com with your actual domain:
<VirtualHost *:80>
ServerAdmin admin@your_domain.com
DocumentRoot /var/www/nextcloud/
ServerName your_domain.com
<Directory /var/www/nextcloud/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/nextcloud
SetEnv HTTP_HOME /var/www/nextcloud
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable necessary modules and the Nextcloud site:
sudo a2ensite nextcloud.conf
sudo a2enmod rewrite headers env dir mime
sudo systemctl reload apache2
Step 6: Secure with SSL using Let’s Encrypt
To enable HTTPS for free, install Certbot and get a certificate:
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d your_domain.com
This will automatically configure SSL for your domain.

Step 7: Complete Installation via Web Interface
Now, finish the setup through a web browser:
- Visit
http://your_domain.com
orhttps://your_domain.com
if SSL is configured. - Enter a username and password for the admin account.
- Use the following database settings:
- Database user: ncuser
- Database password: your_password
- Database name: nextcloud
- Database host: localhost
- Click on Finish Setup.

Optional: Install Recommended Apps
Nextcloud includes a marketplace with collaborative tools such as:
- OnlyOffice or Collabora Online for document editing
- Calendar and Mail for productivity
- Contacts and Tasks for organization
Conclusion
And that’s it! You’ve set up a private cloud using Nextcloud on Ubuntu or Debian. Now you can upload files, create user accounts, and even synchronize data across devices. Your data is stored securely on your own terms, offering a level of control that public cloud services simply can’t match.
Enjoy your new private cloud!