How to install Nextcloud on Debian 12

Installing Nextcloud on Debian is easy to do and takes just a few steps. You’ll set up the actual cloud solution which is protected by various security mechanisms.

Nextcloud for Debian

Nextcloud is a recommended free cloud computing solution that provides plenty of options for both private and commercial use. Among the advantages of the software are strong security features for data protection, such as SSL/TLS encryption, two-factor authentication and GDPR compliance, as well as the choice between local private servers or outsourced host servers. Like many Nextcloud alternatives, the OwnCloud fork supports all common operating systems and offers easy integration of numerous services.

Here, we’ll explain how to set up Nextcloud on Debian 12 step by step. To do this, install an Apache2 web server, a MariaDB server and PHP 8.2. For security purposes, we’ll show you how to set up an Uncomplicated Firewall (UFW) and the required SSL/TLS certificates.

Tip

To install Nextcloud on Ubuntu, you can find the appropriate instructions for Nextcloud setup on Ubuntu 22.04 in our Digital Guide. Check out how to install Nextcloud on Docker here.

What requirements must be met?

There are just a few requirements to install Nextcloud on Debian 12. You need a server with Debian 12 installed. This requires at least 4 gigabytes of RAM and two CPUs. It’s also important that you have non-root user access with administrator rights and set up a domain name that can point to the server’s IP address.

Install Apache2 web server

First, install an Apache2 web server. To do this, update the Debian package index to download the latest version. You can use the command apt update for this:

sudo apt update
bash

Now, execute installation of the latest Apache2 package using the following command:

sudo apt install apache2
bash

Confirm the installation with [y] and press [Enter] to initiate the installation.

After installation, check the status of the service using the following systemctl commands:

sudo systemctl is-enabled apache2
sudo systemctl status apache2
bash

With the first command, you should see the service launch automatically when you boot the system. The status ‘active’ indicates that Apache2 is ready for use.

Install Firewall

Protect your system and your data with a firewall. We recommend the Uncomplicated Firewall (UFW). To set it up as a default, open ports for OpenSSH, HTTP and HTTPS. Now, install the UFW package with the following command:

sudo apt install ufw
bash

Confirm with [y] and complete the installation with [Enter]. Then activate OpenSSH and UFW with:

sudo ufw allow OpenSSH
sudo ufw enable
bash

To start UFW, confirm with [y]. A message stating that firewall is active and enabled on system startup will now appear. Then add the HTTP and HTTPS ports for use by the web server. To do this, execute this command:

sudo ufw allow "WWW Full"
bash

Load UFW again:

sudo ufw reload
bash

To view activated rules, launch the status of UFW. WWW Full should be activated here.

sudo ufw status
bash
Managed Nextcloud from IONOS Cloud
Work together in your own cloud
  • Industry-leading security
  • Communication and collaboration tools
  • Hosted and developed in Europe

Activate PHP 8.2

For the best possible performance and maximum compatibility, Nextcloud recommends PHP 8.2. This is included by default in Debian 12, so you only need to install the necessary packages. The corresponding command is:

sudo 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 libmagickcore-dev
bash

Confirm with [y] and [Enter]. Check the PHP version and activate the extensions:

php --version
php -m
bash

Now launch the PHP configuration file with the nano editor:

sudo nano /etc/php/8.2/apache2/php.ini
bash

You can now make changes and adapt the configuration to suit your needs. Depending on how you want to use Nextcloud on Debian 12, other values may be recommended. In this case, change the settings accordingly. The commands look like this.

Set up the time zone:

data.timezone = Europe/Amsterdam
bash

Amend the parameters for memory_limit, upload_max_filesize, post-max_size and max_execution_time:

memory_limit = 512M
upload_max_filesize = 500M
post_max_size = 600M
max_execution_time = 300
bash

Now activate file_uploads and allow_url_fopen. In both cases, the value should be set to ‘On’:

file_uploads = On
allow_url_fopen = On
bash

Deactivate display_errors and output_buffering and set the respective values to ‘Off’:

display_errors = Off
output_buffering = Off
bash

Activate PHP OPCache using the following command:

zend_extension=opcache
bash

Paste the configuration in the opcache section recommended by Nextcloud for Debian 12:

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
bash

Finally, save the file and exit the nano editor. Now restart the Apache2 service:

sudo systemctl restart apache2
bash

Set up MariaDB server

Nextcloud uses a MariaDB server as the database. Install it with this command:

sudo apt install mariadb-server
bash

Confirm with [y] and [Enter]. After successful installation, enter:

sudo systemctl is-enabled mariadb
sudo systemctl status mariadb
bash

If the server is running smoothly, secure the system. Use the following command to create a root password, remove anonymous users and delete the test database:

sudo mariadb-secure-installation
bash

Adjust settings by pressing [y] to accept and [n] to reject.

Create database and users

Now you can create a new database and the corresponding user. To log in to the MariaDB server, use the following command and enter your root password:

sudo mariadb -u root -p
bash

Use the following commands to create a new database, a user, and the corresponding password:

CREATE DATABASE nextcloud_db;
CREATE USER nextclouduser@localhost IDENTIFIED BY 'yourPassword';
GRANT ALL PRIVILEGES ON nextcloud_db.* TO nextclouduser@localhost;
FLUSH PRIVILEGES;
bash

Replace ‘yourPassword’ with a strong password of your choice. Finally, check whether ‘nextclouduser’ can access the ‘nextcloud_db’ database:

SHOW GRANTS FOR nextclouduser@localhost;
bash

Download current source codes

Download the current source codes to be able to use Nextcloud on Debian 12:

sudo apt install curl unzip -y
bash

Swap to the /var/www directory and download the latest source code:

cd /var/www/
curl -o nextcloud.zip https://download.nextcloud.com/server/releases/latest.zip
bash

Unzip the file and change the owner of the directory under www-data:

unzip nextcloud.zip
sudo chown -R www-data:www-data nextcloud
bash

Configure Apache2 host

Now configure a virtual Apache2 host. Use this nano command:

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

Customise the domain name and the ErrorLog and CustomLog parameters. Replace the placeholder ‘example’ with your domain name.

<VirtualHost *:80>
    ServerName nextcloud.example.io
    DocumentRoot /var/www/nextcloud/
    # log files
    ErrorLog /var/log/apache2/files.example.io-error.log
    CustomLog /var/log/apache2/files.example.io-access.log combined
    <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>
</VirtualHost>
bash

Save the changes and exit the editor. Then activate the configuration using the following command:

sudo a2ensite nextcloud.conf
sudo apachectl configtest
bash

When you receive the output ‘Syntax OK’, restart Apache2 and apply the configuration of the host to it:

sudo systemctl restart apache2
bash

Security with SSL/TLS

You can now use Nextcloud on Debian 12 via an unsecured HTTP protocol. It’s recommended to set up HTTPS to protect your data. To do this, select:

sudo apt install certbot python3-certbot-apache
bash

Generate an SSL certificate by replacing the placeholder ‘example’ with your domain name again:

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email user@example.io -d nextcloud.example.io
bash

Complete the Nextcloud on Debian 12 installation

You can now complete the installation of Nextcloud on Debian 12. To do this, open your web browser and enter the domain name of your Nextcloud installation. Enter a username and your password to create an administrator. Then enter the name of your database, the username and the password and hit ‘Install’. You may download some compatible apps or skip this for now. You’ll be redirected to your dashboard and can now use Nextcloud.

Was this article helpful?
Page top