# 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](https://www.ionos.com/digitalguide/server/tools/what-is-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](https://www.ionos.com/digitalguide/server/tools/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](https://www.ionos.com/digitalguide/server/configuration/nextcloud-ubuntu-2204/) in our Digital Guide. Check out [how to install Nextcloud on Docker](https://www.ionos.com/digitalguide/server/configuration/nextcloud-installation-with-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:

```bash
sudo apt update
```

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

```bash
sudo apt install apache2
```

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:

```bash
sudo systemctl is-enabled apache2
sudo systemctl status apache2
```

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](https://www.ionos.com/digitalguide/server/security/what-is-a-firewall/). We recommend the Uncomplicated Firewall (UFW). To set it up as a default, open ports for OpenSSH, HTTP and [HTTPS](https://www.ionos.com/digitalguide/hosting/technical-matters/what-is-https/). Now, install the UFW package with the following command:

```bash
sudo apt install ufw
```

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

```bash
sudo ufw allow OpenSSH
sudo ufw enable
```

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:

```bash
sudo ufw allow "WWW Full"
```

Load UFW again:

```bash
sudo ufw reload
```

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

```bash
sudo ufw status
```

## 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:

```bash
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
```

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

```bash
php --version
php -m
```

Now launch the PHP configuration file with the nano editor:

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

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:

```bash
data.timezone = Europe/Amsterdam
```

Amend the parameters for memory\_limit, upload\_max\_filesize, post-max\_size and max\_execution\_time:

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

Now activate file\_uploads and allow\_url\_fopen. In both cases, the value should be set to “On”:

```bash
file_uploads = On
allow_url_fopen = On
```

Deactivate display\_errors and output\_buffering and set the respective values to “Off”:

```bash
display_errors = Off
output_buffering = Off
```

Activate PHP OPCache using the following command:

```bash
zend_extension=opcache
```

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

```bash
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
```

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

```bash
sudo systemctl restart apache2
```

## Set up MariaDB server

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

```bash
sudo apt install mariadb-server
```

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

```bash
sudo systemctl is-enabled mariadb
sudo systemctl status mariadb
```

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:

```bash
sudo mariadb-secure-installation
```

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:

```bash
sudo mariadb -u root -p
```

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

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

Replace “yourPassword” with a strong password of your choice. Finally, check whether “nextclouduser” can access the “nextcloud\_db” database:

```bash
SHOW GRANTS FOR nextclouduser@localhost;
```

## Download current source codes

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

```bash
sudo apt install curl unzip -y
```

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

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

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

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

## Configure Apache2 host

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

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

Customize the domain name and the ErrorLog and CustomLog parameters. Replace the placeholder “example” with your domain name.

```bash
<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>
```

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

```bash
sudo a2ensite nextcloud.conf
sudo apachectl configtest
```

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

```bash
sudo systemctl restart apache2
```

## 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:

```bash
sudo apt install certbot python3-certbot-apache
```

Generate an [SSL certificate](https://www.ionos.com/digitalguide/websites/website-creation/ssl-certificate/) by replacing the placeholder “example” with your domain name again:

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

## 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.


This is a markdown version of: [https://www.ionos.com/digitalguide/server/configuration/nextcloud-debian-12/](https://www.ionos.com/digitalguide/server/configuration/nextcloud-debian-12/) for AI/LLM consumption.