How to install NextCloud on debian 11/12 | The Ultimate Guide

NextCloud is a PHP-based web open-source workaround. It runs on the LAMP (Linux, Apache, MySQL/MariaDB, PHP) stack. All the needed info is being discussed here.

Updated: 02 Mar, 24 by Lisa P 10 Min

List of content you will read in this article:

For Debian installing nextcloud is necessarily a good choice. In this tutorial, we will learn how to install Nextcloud on Debian 11 to create your own file hosting and collaboration platform. A very interesting project for those who want to keep control of their data and avoid paying for a proprietary solution! Thanks to a system of applications (plugins), the functionalities of Nextcloud can be extended, which makes it possible to cover a maximum of needs.

In this stage of the task you should consider installing next cloud step by step; there you go:

Installing packages

We must start by installing the packages necessary for the proper functioning of the web server. Let's update the package cache and the machine packages:

apt-get update

apt-get upgrade

Then, we will install Apache2, MariaDB Server, and PHP 8.1 as well as a set of useful PHP extensions:

apt-get install apache2 mariadb-server php8.1 php8.1-common php8.1-curl php8.1-gd php8.1-intl php8.1-mbstring php8.1-xmlrpc php8.1-mysql php8.1- xml php8.1-cli php8.1-zip

Depending on the applications and functions you plan to use, it may be necessary to install other PHP extensions afterward.

To be sure that the PHP 8.1 extension is active in Apache2, run this command:

a2enmod php8.1

We will also install the "wget" and "unzip" packages useful for downloading Nextcloud sources and decompressing the ZIP archive.

apt-get install wget unzip

Prepare Nextcloud sources

install Nextcloud on Debian needs some preparations. We must retrieve the Nextcloud installation sources and position them at the root of the web server, namely in "/var/www/html". Here, we will have the "nextcloud" folder, which implies that to access the application you will have to use this URL:

  http://<server IP>/nextcloud/

Still on the Debian server, go to the "/tmp" directory to download the latest version of Nextcloud with wget:

cd /tmp


Unzip the downloaded ZIP archive:


This results in a "nextcloud" folder in "/tmp" that we will move in its entirety to "/var/ww/html/".

mv nextcloud/ /var/www/html/

All that remains is to change the owner of the Nextcloud data to the Apache2 user:

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

The installation sources are in place. Let's move on.

You will need to create an Apache virtual host configuration file to serve NextCloud.

You can create it with the following command:

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

Add the following lines:

<Virtual Host *:80>

            Server administrator

            DocumentRoot /var/www/html/nextcloud/

            Server name

            Alias /nextcloud "/var/www/html/nextcloud/"

            <Directory /var/www/html/nextcloud/>

            Options + Follow Symbolic Links

 Allow Replace All

      Demand that everything be granted

            <IfModule mod_dav.c>

            David off


            SetEnv HOME /var/www/html/nextcloud

            SetEnv HTTP_HOME /var/www/html/nextcloud


            Error Log ${APACHE_LOG_DIR}/error.log

            CustomLog ${APACHE_LOG_DIR}/access.log combined


Save and close the file when finished. Next, enable the Apache virtual host file and other required modules with the following commands:

-        a2ensite nextcloud.conf

-        a2enmod rewrite

-        a2enmod headers

-        a2enmod env

-        a2enmod directory

-        a2enmod mime

Finally, restart the Apache service to apply the new configuration:

systemctl restart apache2

Installing Nextcloud on Debian at this stage can be a little bit complicated while through this guide to Debian install Nextcloud you will bring it off. We also suggest reading the cheat sheet of the commands through this post.

install Nextcloud on Debian needs a database as well. The MariaDB instance must be configured: we must create a database dedicated to Nextcloud and a specific user who will have rights only on this database. But, before that, we are going to run the MariaDB security script, which will allow us to change the root password in particular.

Run the command below and let yourself be guided. If you need help, look at this article.


Once done, log in to your MariaDB instance with the root account and the password you just set.

mysql -u root –p

After authentication, you have access to the MariaDB prompt. We must start by creating a database that we will call "db23nextcloud".

Overall, for Debian installing Nextcloud is much needed and till this stage, you got halfway off the path.

CREATE DATABASE db23nextcloud;

The next stage of Nextcloud install Debian starts with the task, we will create a user named "usr23nextcloud" who will have the password "Password14" and who will have all the rights on the "db23nextcloud" database. Personalize this information, of course.

GRANT ALL ON db23nextcloud.* TO 'usr23nextcloud'@'localhost' IDENTIFIED BY 'Password14';

Update permissions:


Then, we disconnect from the MariaDB instance:


Everything is ready, we will be able to finalize the installation of Nextcloud using a browser. With your favorite browser, access the following address:

http://<server IP>/nextcloud/

You should arrive on a page like the one below. Here, you will need to define a username and password for the main Nextcloud Administrator account.

Then, a little lower in the database, you must indicate the connection information to the MariaDB server. Here, we reuse the information defined previously, as in the image below. Click "Install" when done. install Nextcloud on Debian has to be finished.

A few seconds later, the installation is complete, welcome to your Nextcloud server!

From now on you can create new files, or load existing files. There are also synchronization clients for workstations, as well as mobile applications.

Finally, the installation of a free "Let's encrypt" certificate so that our site is secure and the traffic redirected in HTTPS.

apt install -y certbot python3-certbot-apache

To generate the certificate:

certbot --apache -d

Note: Replace with the name of the domain to be certified.

All you have to do is answer the questionnaire and the certificate will be generated:

" - Congratulations! Your certificate and chain have been saved at:


    Your key file has been saved at:


    Your certificate will expire on 2022-10-01. To obtain a new gold

    tweaked version of this certificate in the future, simply run

    certbot again with the "certonly" option. To non-interactively

    renew *all* of your certificates, run "certbot renew"

  - If you like Certbot, please consider supporting our work by:

    Donating to ISRG / Let's Encrypt:

    Donating to EFF:

Extra tip

That's it, the basic installation of Nextcloud on Debian 10 to 12 is done! For nextcloud install, Debian is a good choice. However, you still have work to do if it's a server that needs to be set up in production: Apache2 security, switching the site to HTTPS, setting up a domain name, installing CrowdSec to detect and block attacks, etc.

My recommendations after installing Nextcloud on Debian 11:

-        Use a firewall like UFW or IP tables

-        Open access to Nextcloud only from a Reverse Proxy server

-        Securing Apache2 on the Lamp server.

You can also link your Nextcloud access with your Active Directory to allow your employees to connect with the same Windows credentials and other services that use an LDAP link.

Final Words

In this post, we have explained to you step by step how to install Nextcloud on Debian. If you have any ideas in this field, i.e. installing NextCloud on Debian 11 or Debian 12, be sure to contact us.

Lisa P

Lisa P

Hello, everyone, my name is Lisa. I'm a passionate electrical engineering student with a keen interest in technology. I'm fascinated by the intersection of engineering principles and technological advancements, and I'm eager to contribute to the field by applying my knowledge and skills to solve real-world problems.