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 update
bashNow, execute installation of the latest Apache2 package using the following command:
sudo apt install apache2
bashConfirm 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
bashWith 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
bashConfirm with [y] and complete the installation with [Enter]. Then activate OpenSSH and UFW with:
sudo ufw allow OpenSSH
sudo ufw enable
bashTo 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 reload
bashTo view activated rules, launch the status of UFW. WWW Full should be activated here.
sudo ufw status
bash- 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
bashConfirm with [y] and [Enter]. Check the PHP version and activate the extensions:
php --version
php -m
bashNow launch the PHP configuration file with the nano editor:
sudo nano /etc/php/8.2/apache2/php.ini
bashYou 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
bashAmend 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
bashNow activate file_uploads and allow_url_fopen. In both cases, the value should be set to ‘On’:
file_uploads = On
allow_url_fopen = On
bashDeactivate display_errors and output_buffering and set the respective values to ‘Off’:
display_errors = Off
output_buffering = Off
bashActivate PHP OPCache using the following command:
zend_extension=opcache
bashPaste 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
bashFinally, save the file and exit the nano editor. Now restart the Apache2 service:
sudo systemctl restart apache2
bashSet up MariaDB server
Nextcloud uses a MariaDB server as the database. Install it with this command:
sudo apt install mariadb-server
bashConfirm with [y] and [Enter]. After successful installation, enter:
sudo systemctl is-enabled mariadb
sudo systemctl status mariadb
bashIf 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
bashAdjust 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
bashUse 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 -y
bashSwap 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
bashUnzip the file and change the owner of the directory under www-data:
unzip nextcloud.zip
sudo chown -R www-data:www-data nextcloud
bashConfigure Apache2 host
Now configure a virtual Apache2 host. Use this nano command:
sudo nano /etc/apache2/sites-available/nextcloud.conf
bashCustomise 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 configtest
bashWhen you receive the output ‘Syntax OK’, restart Apache2 and apply the configuration of the host to it:
sudo systemctl restart apache2
bashSecurity 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
bashGenerate 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
bashComplete 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.