How to Install Nextcloud on Debian 11

Nextcloud is open-source software for creating public and private file storage. It allows you to create your self-hosted services like Dropbox, Google Drive, or Originally, it's created by the original owncloud developer Frank Karlitschek. In 2016, he forks the Owncloud project and creates a new project with the new name "Nextcloud"

By this time, the Nextcloud project growing rapidly and becoming more than file hosting software, it's more like a file sync and content collaboration platform. Backed with a lot of plugins, Nextcloud becomes such a powerful collaboration software. You can install plugins for project management, video conferencing, collaborative editing, note-taking, email client, etc.

In this guide, you will learn how to install Nextcloud on the latest Debian 11 Bullseye. You will be installing Nextcloud under the LAMP Stack (Linux, Apache2/httpd, MySQL/MariaDB, and PHP).


  • A Debian 11 server. Ensure all packages are updated to the latest version.
  • A root user or a user with root privileges. This user will be used for installing new packages and editing system configurations.

Get Root and Update Repositories

First, execute the following command to get the root privileges.

1. If you have 'sudo' installed, execute the sudo command below.

sudo su

Now type the password login for your user.

2. If you don't have the sudo package, execute the 'su' command as below


Now type your root password and press 'Enter'.

3. After that, update all your Debian repositories using the apt command below.

apt update

Installing Apache Web Server

After updating Debian repositories, you will be installing an apache web server and enabling some Apache modules for Nextcloud.

1. Execute the apt command below to install the apache web server.

apt install apache2

Type 'y' and press 'Enter' to continue the installation.

Install Apache Web Server

2. If the installation is complete, check the apache service using the following command.

systemctl is-enabled apache2
systemctl status apache2

You will see the output 'enabled', which means the apache service will automatically start at system startup. And the current state of the apache service, it's 'active (running)'.

Checking Apache Service Statys

3. Next, enable Apache modules 'ssl, rewrite, and headers' by executing the a2enmod command below.

a2enmod ssl rewrite headers

Below is the output you will get.

Enable some modules apache

4. After that, execute the following command to restart the apache service.

systemctl restart apache2

New apache modules will be applied, verify those modules using the apachectl command below.

apachectl -M | egrep "ssl|rewrite|headers"

You will see similar output as below.

Verify modules enabled apache

Installing and Configuring PHP

For this guide, you will be deploying Nextcloud with the latest stable version of PHP 8.0.

By default, the Debian repository provides packages for PHP 8.0. But, Nextcloud requires some additional PHP packages that can be installed from a 3rd-party repository. And you will be adding a new repository to your Debian system.

1. Execute the command below to add a PHP repository for the Debian system.

echo "deb $(lsb_release -sc) main"\
| sudo tee /etc/apt/sources.list.d/sury-php.list

Download the GPG key to the '/etc/apt/trusted.gpg.d' directory.

curl -o /etc/apt/trusted.gpg.d/sury-php8.gpg

Now run the 'apt update' command again to update all repositories.

apt update

Add PHP Repository Debian 11

2. Install PHP packages and additional PHP modules for Nextcloud using the apt command below.

apt install -y php php-curl php-cli php-mysql php-gd php-common php-xml php-json php-intl php-pear php-imagick php-dev php-common php-mbstring php-zip php-soap php-bz2 php-bcmath php-gmp php-apcu

After that, execute the apt command again for installing some additional packages.

apt install -y libmagickcore-dev

The 'libmagickcore-dev' packages are needed by the php-imagick for SVG image processing on Nextcloud.

3. If all packages installation is complete, change the working directory to '/etc/php/8.0/apache2' and edit the configuration 'php.ini' using nano.

cd /etc/php/8.0/apache2/
nano php.ini

For the basic nextcloud deployment, change the default options using the following configuration.

file_uploads = On
allow_url_fopen = On
memory_limit = 512M
upload_max_filesize = 500M
post_max_size = 600M
max_execution_time = 300
display_errors = Off
date.timezone = Europe/Amsterdam
output_buffering = Off

Uncomment the 'zend_extension=opcache' option to load the opcache extension.


Move to the '[opcache]' section and add the following configuration.

opcache.enable = 1
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 10000
opcache.memory_consumption = 128
opcache.save_comments = 1
opcache.revalidate_freq = 1

Save the configuration by pressing the 'Ctrl+x' button and type 'y', then press 'Enter' to exit.

4. Now restart the apache service to apply new changes using the command below.

systemctl restart apache2

Configuring PHP

Installing and Configuring MariaDB

For this stage, you will be installing the mariadb database server, securing mariadb deployment, and creating a new database and user for Nextcloud.

1. To install the mariadb database server, run the command below.

apt install mariadb-server mariadb-client

Type 'y' to confirm and install mariadb packages.

Installing MariaDB Server Debian 11

2. Once the installation is complete, check the mariadb service using the following command.

systemctl is-enabled mariadb
systemctl status mariadb

The mariadb service is active and running, and it's enabled to start automatically at system startup.

Checking MariaDB Database Service

3. Next, you need to secure your mariadb deployment by setting up the root password for mariadb and remove some default configuration. To do that, you can use the command-line tool 'mysql_secure_installation', which is included on the default mariadb installation.

Execute the "mysql_secure_installation" command below.


At the first, you will be asked to enter the mariadb root password. Just press 'Enter' to continue.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Type 'Y' to enable the 'unix_socket' authentication for the user 'root'.

Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
 ... Success!

Type your strong mariadb root password and repeat, then press "Enter" to continue.

Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

Now type "Y" and press "Enter" to remove the default anonymous user from the mariadb server.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

After that, disable the remote login for the default user 'root'. Type "Y" and press "Enter" to continue.

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

Type "Y" again to remove the default database "test" and press "Enter".

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

And the last, type "Y" again to reload all tables privileges to apply a new configuration.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Now the process is complete and you will see the following output.

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Creating Database and User for Nextcloud

1. log in to the mariadb shell using the mysql command below.

mysql -u root -p

2. Now execute the following mysql query to create a new database "nextcloud_db".

CREATE DATABASE nextcloud_db;

3. Execute the following query to create a new database user "nextclouduser". Change the "strongpassword" with your strong password.

CREATE USER [email protected] IDENTIFIED BY 'StrongPassword';

4. Allow the user "nextclouduser" to access and write the "nextcloud_db" using the following query.

GRANT ALL PRIVILEGES ON nextcloud_db.* TO [email protected];

5. Now reload all tables privileges to apply the new database configuration.


Then you can type "quit" and press "Enter" to exit from the mariadb shell.

Create new database and user for Nextcloud

Download Nextcloud Source Code

1. Change the working directory to "/var/www" and download the latest version of Nextcloud source code using the wget command as below.

cd /var/www/
curl -o

Download Nextcloud Source Code

2. Now install the unzip package using the following command.

apt install unzip

3. Next, extract the Nextcloud source code "" and you will get a new directory "nextcloud", then change the owner of the "nextcloud" directory to "www-data" user.

chown -R www-data:www-data nextcloud

Now you're ready to generate SSL Letsencrypt and configuring apache virtual host for Nextcloud.

Generating SSL Letsencrypt

In this stage, you will be installing the certbot tool and generate the SSL certificates for the Nextcloud installation. You will be generating SSL Letsencrypts with the webroot plugin.

1. Execute the following command to install the certbot tool for generating SSL Letsencrypt.

apt install certbot

Type 'y' and press 'Enter' to continue the installation.

Install Certbot

2. Once the installation is complete, create a new directory for letsencrypt authorization using the following commands.

mkdir -p /var/lib/letsencrypt/.well-known
chgrp www-data /var/lib/letsencrypt
chmod g+s /var/lib/letsencrypt

3. Next, change the working directory to the "/etc/apache2/conf-available/" and create a new configuration "well-known.conf" using nano.

cd /etc/apache2/conf-available/
nano well-known.conf

Copy and paste the following configuration.

Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
<Directory "/var/lib/letsencrypt/">
    AllowOverride None
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS

Press "Ctrl+x" and type "y" and press 'Enter' to save the configuration and exit.

Now activate the new configuration by creating a symlink of the 'well-known.conf' file to the directory 'conf-enabled' using the 'ln' command below.

ln -s /etc/apache2/conf-available/well-known.conf /etc/apache2/conf-enabled/

4. Now execute the following commands to verify the apache configuration and restart the apache service.

apachectl configtest
systemctl restart apache2

If you've no error, you're ready to generate SSL Letsencrypt with the webroot plugin.

Setup SSL Verification for Letsencrypt

5. Before generating SSL Letsencrypt, ensure your domain name is resolved to the server IP address. After that, you can generate SSL Letsencrypt with the webroot plugin by running the certbot command below. Also, change the email address and domain name to your own.

sudo certbot certonly --agree-tos --email [email protected] --webroot -w /var/lib/letsencrypt/ -d

When the process is complete, your SSL certificates are available at the "/etc/letsencrypt/live/" directory.

Setup Apache Virtual Host for Nextcloud

In this step, you will be adding a new apache/httpd virtual host configuration for Nextcloud.

1. Change the working directory to "/etc/apache2/sites-available/" and create new configuration "nextcloud.conf" using nano.

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

Change the detail domain name and SSL path directory to your own and paste the configuration to the "nextcloud.conf" file.

<VirtualHost *:80>

    # auto redirect HTTP to HTTPS
    Redirect permanent /

<VirtualHost *:443>
    DocumentRoot /var/www/nextcloud/

    Protocols h2 http/1.1

    # auto redirect www to non-www
    <If "%{HTTP_HOST} == ''">
        Redirect permanent /

    # log files
    ErrorLog /var/log/apache2/
    CustomLog /var/log/apache2/ combined

    SSLEngine On
    SSLCertificateFile /etc/letsencrypt/live/
    SSLCertificateKeyFile /etc/letsencrypt/live/

    # HSTS
    <IfModule mod_headers.c>
        Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"

    <Directory /var/www/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All

        <IfModule mod_dav.c>
            Dav off

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

Press "Ctrl+x" and type "Y", then press 'Enter' to save the configuration and exit.

2. Now activate the 'nextcloud.conf' virtual host configuration by executing the following command.

a2ensite nextcloud.conf

Setup virtual host for Nextcloud

3. Now verify the new apache configuration and make sure you have no error, then restart the apache service.

apachectl configtest
systemctl restart apache2

Verify Apache configuration and restart service

Nextcloud Installation

If all related server configuration is complete, you can access your Nextcloud installation with the web browser.

1. Open your web browser and type the URL address of your Nextcloud installation.

Create your first and admin user for Nextcloud and the data directory is writable by the user 'www-data'.

Create Admin Account Nextcloud

2. Scroll the page to the bottom, type details database name, user, and the password. For the option 'Install recommended apps', uncheck it to make installation faster. Then click the 'Finish setup' button to install Nextcloud.

Setting up database and fisnish nextcloud installation

3. If the installation is successful, you will see the Nextcloud dashboard as below.

Nextcloud userfiles dashbaird

4. Now click the user icon at the top right and click the menu 'Settings'.  At the 'Administration' section, click 'Overview'.

Nextcloud administration overview

  • At the 'Security and setup warnings' section, you will some recommendation that you need to do, depends on your installation environment.
  • At the 'Versions' section, you will see the current branch of your Nextcloud installation.

5. Next, click the menu 'System' at the bottom of the 'Administration' section.

Nextcloud system status

You will see details of your environment, system load, disk space status, memory status, network status, etc.

6. As said before, the nextcloud has become more than just file sync. With the support of additional apps/plugins, it's become a collaboration suit.

At the profile icon top right, click the menu 'Apps', and you will see nextcloud apps store as below.

Nextcloud apps installation

Choose the apps you want to install, then click the button 'Download and enable' to install new apps.

7. Below is the default view of the Nextcloud user dashboard. You can extend the functionality of your dashboard by installing additional plugins.

Nextcloud home dashboard

Nextcloud Performace Tuning

After installed Nextcloud, you can do some steps further to increase the Nextcloud performance by enabling the local memory cache and setting up a cronjob for Nextcloud itself.

1. At the top PHP installation section, you already set up the PHP for caching. To enable caching on Nextcloud, edit the Nextcloud configuration "config.php".

Change the working directory to "/var/www/nextcloud/config" and edit the configuration "config.php" using nano editor.

cd /var/www/nextcloud/config/
nano config.php

Add following configuration inside the 'array ( .. );' bracket as below

$CONFIG = array (
  # Additional configuration
  'memcache.local' => '\OC\Memcache\APCu',

Now press the "Ctrl+x" button and type "y", then press 'Enter' to save the configuration and exit.

2. A Nextcloud system needs to run some background tasks on regular basis and without any user/admin interaction. To do that, you can use the cronjob for task scheduler Nextcloud tasks.

On the Debian Linux system, the default apache installation is running under the user is "www-data". Create a new cronjob for user "www-data" using the command below.

crontab -u www-data -e

If you've multiple editors on your system, choose the editor as your comfortable use. For this guide, we will be using a nano editor.

Setup cron

Add the following configuration.

*/5  *  *  *  * php -f /var/www/nextcloud/cron.php

Save the configuration and exit.

Cronjob configuration you must know:

  • This cronjob configuration allows user "www-data" to execute the PHP script "/var/www/nextcloud/cron.php" every 5 minutes.

To verify the cronjob configuration, you can execute the following command.

crontab -u www-data -l

If your configuration is a success, you will get the configuration on top as your output. Otherwise, you will get a blank result.

Verify cron for Nextcloud


Congratulation! You have successfully installed Nextcloud on Debian 11 Bullseye. The Nextcloud server is running under the LAMP Stack with SSL enabled. Also, your Nextcloud installation is running with memory caching enabled with PHP APC and opcache extensions.

Share this page:

14 Comment(s)

Add comment

Please register in our forum first to comment.


By: Cyth

It would be nice if you included how to get the php-smbclient working in debian 11. That would be a great addition

By: Nurbie

Well darn, tried the directions.  HTTP isnt redirecting and i still get the root apache apge, and HTTPS 'redirected too manytimes"

By: Holy Moly Guacamoly

Hello, Thanks a lot for the tuto, it was amazing ! I learned a lot :) Nurbie, for removing the root apache page, you will have to disable 000-default.conf config, which point to index.html. The command a2dissite can help. check how it works on the web and don't forget to restart apache, exactly like he explain when you enable (a2ensite) nextcloud.conf :)

By: Fredrik

Took me a while to figure out that there is a typo here "CREATE DATABASE netxcloud_db;", but the guide worked a lot better after fixing that issue. Thanks.

By: EricG

Great tutorial, and a very interesting subject!  Thanks much for offering it.  I'm stuck at the "ensure your server IP is resolved to your domain name".  Haven't found answer to that yet....Also, I don't have a 'static' ISP address-  it is Carrier Grade NAT- and I am not knowing if I can get through that situation.  Oh well-  Any comments would be appreciated.  /E

By: Stefan

This tutorial will lead to an installation of PHP 8.1.2. However, current versions of NextCloud will be not working and break with this error:

"This version of Nextcloud is not compatible with > PHP 8.0."

See related issue here:

Support PHP8.1 #29287

By: deschriever

You can install nextcloud 24.0.0 to Use PHP 8.1 with ;)

curl -o

By: Gary Dale

I'm trying to follow your guide to install Nextcloud on my Debian/Bullseye box but when get to actually acccessing the Nextcloud installation, I get the source code for the index.php file instead of the web page.

I did make two changes to the installation process: 1) I called the server "nextcloud" rather than "files"2) my document root for my local web sites is not /var/www/ but rather a different root that I have been using for several other sites.

Also, I note that the PHP installation seems to be 8.1, not 8.0 and used the /etc/php/8.1/ directory instead of /etc/php/8.0 for the php.ini setup. As per the suggestion by deschriever, I installed nextcloud 24 to compenstate.

I've gone through this process several times now and can't seem to figure out where I went wrong. Can you help?

By: Gary Dale

EricG:A lot of home users don't have a static IP address. However I have noted that home iP addresses don't change very often. This allows me to register a domain and point it to my home server. In the case of this tutorial, that would mean creating an A record in the registrar's DNS to point to files.. You also will need to open ports 80 and 443 on your home router to forward to your home server's internal (LAN) address.

I also run a cron job hourly that checks for an IP address change and send me an e-mail if it does. This is simply a matter of saving your current external IP address, using curl to pull a web page from a service like "whatsmyip.prg', extracting the current IP and sending an e-mail if if doesn't match the saved one. Here's some sample code for that:#!/bin/sh cd /root curl -s | grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' > cur-ip  if [ -s cur-ip ]; then   if ! cmp cur-ip old-ip; then      mail -s "home IP change" [email protected] < cur-ip      cp cur-ip old-ip   fi else   cp old-ip cur-ip fi

By: Gary Dale

Nevermind. What I was missing is I needed to a2emod php8.1. This wasn't listed in the instructions above. However it appears to be a necessary step it you didn't previously have that version of PHP installed

By: Giuacchinu

Hi, "live" directory, missing from letsencrypt three

By: evanmac

Hi, and thank you for writing this guide, first of all :D

I installed and setup my own NC server usign a macmini 2011, Debian 11 (native OS, not virtualized), and a 2TB external disk (for data) with a firewire box.

Since I need to go back and forth consulting this (and many other) info, I decide to make me a "cookbook" recollecting all the info I used to install and correctly configure the NC server.

I'd like to submit the cookbook to all authors, whom I have used the info to make the cookbook (giving them the credits, ofc).

Now, the question is: How can I contact you (or the rights owner) to submit the preliminar work and then obtain the grant to distributed it (all free/GPL license, this is not a commercial thing)?

Many thanks in advance, evanmac

By: poltpolt

good one but nowadays it takes time to skip php 8.2 which is the default in repo but to high for nextcloud. Lots of manual work required

By: Peter

So Awsome!

Thank you!!!!!