In today’s world, data privacy and control are becoming increasingly important. NextCloud provides an open-source solution for creating your own private cloud storage service. This allows you to store, sync, and share files securely across devices, all while maintaining full control over your data. In this step-by-step guide, we will walk you through the process of installing and configuring NextCloud on an Ubuntu server, ensuring a smooth setup with all necessary components.
Whether you’re setting up NextCloud for personal use or as a business solution, this tutorial will cover everything you need to know to get started with your private cloud storage.
Prerequisites
Before starting, make sure you have the following:
- A server running Ubuntu 22.04 or later.
- Root or sudo access to the server.
- A domain name (optional, but recommended for public access).
- An SSL certificate (we’ll cover this in the tutorial).
Step-by-Step Guide to Installing NextCloud
Here’s the first part of the instruction manual based on the images you have shared. I will detail each step and explain the reasoning behind it.
Step 1: Update and Upgrade the System

sudo apt update -y && sudo apt upgrade -yKeeping your system up-to-date is essential for security and stability. apt update refreshes the package list, while apt upgrade installs the latest versions of the installed packages. The -y flag confirms all prompts automatically.
Step 2: Install Apache Web Server

sudo apt install apache2Apache is one of the most popular web servers. Here, we install it so that it can serve the NextCloud application to users via a web browser.
Step 3: Enable and Start Apache, then Verify Status

sudo systemctl enable apache2 && sudo systemctl start apache2After installing Apache, we need to start the service and enable it to automatically start on boot. systemctl is used to manage services in modern Linux distributions. Enabling it ensures that the web server will restart automatically after a system reboot.
sudo systemctl status apache2To ensure that Apache is running correctly, we use this command to check its status. This should return an “active (running)” status, indicating the web server is operational.
Step 4: Install PHP and Extensions Required by NextCloud

sudo apt-get install php8.1 php8.1-cli php8.1-common php8.1-imap php8.1-redis php8.1-snmp php8.1-xml php8.1-zip php8.1-mbstring php8.1-curl php8.1-gd php8.1-mysqlNextCloud requires PHP to run, along with several additional PHP extensions such as xml, zip, gd, and mysql. This command installs PHP 8.1 and all the necessary modules to ensure that NextCloud functions correctly.
Step 5: Install MariaDB (MySQL Alternative) for Database

sudo apt install mariadb-serverNextCloud requires a database to store its data. MariaDB is a popular, open-source database that is fully compatible with MySQL, making it a suitable backend for NextCloud. This command installs MariaDB on the server.
Step 6: Enable, Start MariaDB, and Verify the Status

sudo systemctl start mariadb && sudo systemctl enable mariadbAfter installing MariaDB, we start the service and enable it to start automatically at boot. Similar to Apache, this ensures that the database service remains running even after the server restarts.
sudo systemctl status mariadbThis command checks if MariaDB is running properly. You should see an “active (running)” status in the output.
Step 7: Configure the Database for NextCloud

sudo mysqlOnce inside the MariaDB shell:
CREATE DATABASE nextcloud;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost' IDENTIFIED BY 'YourStrongPasswordHere';
FLUSH PRIVILEGES;
EXIT;In this step, we create a new database named nextcloud. We also create a user named nextcloud with full privileges over this database. The FLUSH PRIVILEGES; command reloads the privileges, ensuring the new user has the required access. Don’t forget to replace YourStrongPasswordHere with a secure password.
Step 8: Download NextCloud

Navigate to the Web Directory:
cd /var/www/htmlWe start by navigating to the /var/www/html directory, which is the default web root for Apache web server on Ubuntu. This is where we will install NextCloud, so it can be accessible through the web.
Download the Latest Version of NextCloud:
sudo wget https://download.nextcloud.com/server/releases/latest.zipUsing wget, we download the latest release of NextCloud in a zip format. This ensures that you’re always working with the most up-to-date version of the software.
Step 9: Unzip NextCloud Package
If you don’t already have it, Install Unzip Utility:

sudo apt install zip -ySince the NextCloud package is a .zip file, we need the unzip utility to extract the files. If it’s not installed by default on your server, this command installs it. The -y flag is used to auto-confirm the installation.
Unzip NextCloud Package:

sudo unzip latest.zip -d /var/www/html/This command extracts the latest.zip file into the /var/www/html directory, placing all of NextCloud’s files in the nextcloud folder. The -d option specifies the target directory where the files should be unzipped.
Step 10: Move NextCloud Files to the Root Directory and Remove Unnecessary Files

sudo mv /var/www/html/nextcloud/* /var/www/html/After extracting the NextCloud files into the nextcloud directory, we now move them to the web root (/var/www/html/). This allows the application to be accessed directly without the need for a subdirectory in the URL.
sudo rm index.html latest.zipThe index.html file is the default Apache page, and latest.zip is the NextCloud archive we downloaded earlier. Both are no longer needed, so they are removed to keep the directory clean.
Step 11: Set Correct Permissions

sudo chown -R www-data:www-data /var/www/html/NextCloud files must be owned by the www-data user and group (the default user that Apache runs under) to ensure the web server can read and write to the necessary files. The -R flag applies the changes recursively to all files and subdirectories.
Step 12: Create and Configure Apache Virtual Host
Apache Virtual Host Creation

sudo touch /etc/apache2/sites-available/nextcloud.conf
sudo vi /etc/apache2/sites-available/nextcloud.confWe create a new Apache configuration file for NextCloud in the sites-available directory, then open it with vi for editing. This file will configure the Virtual Host for NextCloud.
Configure Apache Virtual Host for NextCloud

Inside the nextcloud.conf file, add the following then hit Escape and then :wq to save and exit the editor:
<VirtualHost *:80>
ServerName domain.com
DocumentRoot /var/www/html/
<Directory /var/www/html/>
Require all granted
Options FollowSymlinks MultiViews
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
</Directory>
ErrorLog /var/log/apache2/domain.com.error_log
CustomLog /var/log/apache2/domain.com.access_log common
</VirtualHost>This Apache Virtual Host configuration tells Apache to serve NextCloud on port 80 for the domain nextcloud.roosho.link (Here use your own domain). It sets the document root to /var/www/html, where NextCloud files are located, and configures logging for the domain. The AllowOverride All directive allows NextCloud to control .htaccess files, necessary for rewriting URLs.
Step 13: Enable Apache Site and Rewrite Module

sudo a2ensite nextcloud.conf
sudo a2enmod rewrite
sudo systemctl restart apache2The a2ensite command enables the newly created NextCloud site configuration. a2enmod rewrite enables Apache’s mod_rewrite, which is crucial for NextCloud to handle URL rewriting. After enabling these modules and configurations, we restart Apache to apply the changes.
Step 14: Access the NextCloud Setup in Browser for Initial Configuration

http://<ip address> After the initial server configuration, you can access your NextCloud instance by typing the server’s IP address or domain into your browser. This will open the NextCloud setup page where you can create an admin account and configure the data folder location.
Initial Configuration
On the setup page:
Create an Admin Account
- Username: Set the admin username (e.g.,
roosho). - Password: Create a secure password.
- Data Folder: Confirm the data folder path as
/var/www/html/data.
During the first access to the NextCloud setup page, you will create an admin account that will have full control over the instance. The data folder is where all user files will be stored. It’s important to confirm that the folder is correctly set to /var/www/html/data (or your preferred data folder).
Configure the Database
- Database Type: Select MySQL/MariaDB.
- Database User: Enter
nextcloud(the user you created earlier in MariaDB). - Database Password: Enter
YourStrongPasswordHere, the password you defined for thenextclouddatabase user. - Database Name:
nextcloud(the name of the database you created earlier). - Database Host:
localhost.
NextCloud requires a database to store its metadata. Here you provide the necessary credentials to connect NextCloud to the MariaDB database you previously set up.
SSL Certificate Configuration for NextCloud
Step 1: Edit NextCloud Configuration File

sudo vi /var/www/html/config/config.php
This step opens the NextCloud configuration file using the vi editor. In this file, you need to define the trusted domains, which includes your server’s IP and any domain names that will be used to access the NextCloud instance. You add the domain nextcloud.roosho.link under the trusted_domains array to allow access from this URL.
Step 2: Install Certbot for SSL Certificate
Update the system as a good SysAdmin:

sudo apt update -yRunning apt update ensures that all package lists are updated. This step guarantees that the latest software versions are installed.
Install Certbot for SSL Certificate:

sudo apt install certbot python3-certbot-apache -yCertbot is a tool used to obtain free SSL certificates from Let’s Encrypt. The package python3-certbot-apache enables Certbot to work with Apache to automatically configure SSL.
Step 3: Obtain and Install SSL Certificate

sudo certbot --apache -d domain.comThis command tells Certbot to obtain an SSL certificate for nextcloud.roosho.link and configure it automatically for Apache. Once completed, your NextCloud site will be served over HTTPS, securing communication between users and the server.
Login to NextCloud to Verify NextCloud Interface

Once setup is complete, you can log in at:
https://domain.comUse the admin credentials (In my case the URL: nextcloud.roosho.link username: roosho, password: your chosen password) to log in.
After completing the setup process, you can now access and log into your NextCloud instance via the browser. This marks the final step of installation, giving you access to the NextCloud dashboard where you can begin uploading files, configuring settings, and adding users.

After logging in, you will see the NextCloud dashboard, as shown in the screenshot. Here, you can:
- View and manage your files and folders.
- Use features like sharing, tagging, and version control.
- Customize your NextCloud instance settings.
The dashboard is where you will spend most of your time managing NextCloud. It’s a web interface for uploading, sharing, and organizing files and managing user accounts and system settings.
Conclusion
Congratulations! You’ve successfully installed and configured NextCloud on your Ubuntu server. With NextCloud, you can securely sync, share, and manage files across all your devices, all while retaining full control over your data. This tutorial covers all the essential steps, from server setup to the installation of necessary software and configuration of your NextCloud instance.
With your NextCloud server up and running, you’re now free to explore its features and capabilities, whether for personal use or to provide a secure cloud solution for your business. Happy clouding!

No Comment! Be the first one.