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.
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 updatebashNow, execute installation of the latest Apache2 package using the following command:
sudo apt install apache2bashConfirm 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 apache2bashWith 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 ufwbashConfirm with [y] and complete the installation with [Enter]. Then activate OpenSSH and UFW with:
sudo ufw allow OpenSSH
sudo ufw enablebashTo 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"bashLoad UFW again:
sudo ufw reloadbashTo view activated rules, launch the status of UFW. WWW Full should be activated here.
sudo ufw statusbash- 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-devbashConfirm with [y] and [Enter]. Check the PHP version and activate the extensions:
php --version
php -mbashNow launch the PHP configuration file with the nano editor:
sudo nano /etc/php/8.2/apache2/php.inibashYou 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/AmsterdambashAmend 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 = 300bashNow activate file_uploads and allow_url_fopen. In both cases, the value should be set to ‘On’:
file_uploads = On
allow_url_fopen = OnbashDeactivate display_errors and output_buffering and set the respective values to ‘Off’:
display_errors = Off
output_buffering = OffbashActivate PHP OPCache using the following command:
zend_extension=opcachebashPaste 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 = 1bashFinally, save the file and exit the nano editor. Now restart the Apache2 service:
sudo systemctl restart apache2bashSet up MariaDB server
Nextcloud uses a MariaDB server as the database. Install it with this command:
sudo apt install mariadb-serverbashConfirm with [y] and [Enter]. After successful installation, enter:
sudo systemctl is-enabled mariadb
sudo systemctl status mariadbbashIf 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-installationbashAdjust 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 -pbashUse 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;bashReplace ‘yourPassword’ with a strong password of your choice. Finally, check whether ‘nextclouduser’ can access the ‘nextcloud_db’ database:
SHOW GRANTS FOR nextclouduser@localhost;bashDownload current source codes
Download the current source codes to be able to use Nextcloud on Debian 12:
sudo apt install curl unzip -ybashSwap 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.zipbashUnzip the file and change the owner of the directory under www-data:
unzip nextcloud.zip
sudo chown -R www-data:www-data nextcloudbashConfigure Apache2 host
Now configure a virtual Apache2 host. Use this nano command:
sudo nano /etc/apache2/sites-available/nextcloud.confbashCustomise 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>bashSave the changes and exit the editor. Then activate the configuration using the following command:
sudo a2ensite nextcloud.conf
sudo apachectl configtestbashWhen you receive the output ‘Syntax OK’, restart Apache2 and apply the configuration of the host to it:
sudo systemctl restart apache2bashSecurity 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-apachebashGenerate 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.iobashComplete 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.

