DebianDebian Based

How To Install Nextcloud on Debian 12

Install Nextcloud on Debian 12

In this tutorial, we will show you how to install Nextcloud on Debian 12. In today’s digital age, data is at the heart of our personal and professional lives. The need for secure, accessible, and customizable cloud storage solutions has never been greater. Nextcloud, a powerful and open-source file-sharing platform, offers the perfect solution.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Nextcloud on a Debian 12 (Bookworm).


  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • Make sure your Debian 12 system is connected to the internet. An active connection is essential for downloading the required packages and updates during the installation.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Nextcloud on Debian 12 Bookworm

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt upgrade

This command updates the package list and upgrades the installed packages to their latest versions.

Step 2. Installing Apache Web Server.

Apache is a popular web server that we’ll use to host Nextcloud. Install Apache using the following command:

sudo apt install apache2

Once installed, start Apache and enable it to start at boot:

sudo systemctl start apache2
sudo systemctl enable apache2

If you’re using a firewall, don’t forget to allow HTTP and HTTPS traffic:

ufw allow 80,443/tcp
ufw reload

Step 3. Installing MySQL Database Server.

Nextcloud requires a database to store its configuration and data. We’ll use MySQL for this purpose. Now install MySQL Server:

sudo apt install mysql-server

After installation, run the MySQL secure installation script:


Follow the on-screen prompts to set the root password, remove anonymous users, disallow root login remotely, and remove test databases and access to them.

We’ll create a database and user for Nextcloud. Log in to MySQL as the root user:

mysql -u root -p

Execute the following SQL commands, replacing [your_db_name], [your_db_user], and [your_db_password] with your preferred values:

CREATE DATABASE [your_db_name];
CREATE USER '[your_db_user]'@'localhost' IDENTIFIED BY '[your_db_password]';
GRANT ALL PRIVILEGES ON [your_db_name].* TO '[your_db_user]'@'localhost';

Step 4. Installing PHP and Required Modules.

Nextcloud relies on PHP and several PHP modules to function correctly. Now install PHP and the required modules:

sudo apt install php libapache2-mod-php php-mysql php-zip php-gd php-json php-curl php-mbstring php-intl php-imagick php-xml php-pear php-redis php-apcu

Then, open the PHP configuration file:

nano /etc/php/8.x/apache2/php.ini

Find and adjust the following settings:

memory_limit = 512M
upload_max_filesize = 1G
post_max_size = 1G
max_execution_time = 360
date.timezone = [your_timezone]

Save and exit the file. Restart Apache to apply the changes:

systemctl restart apache2

Step 5. Install Nextcloud on Debian 12

Now, it’s time to bring Nextcloud to life. Download the latest stable release of Nextcloud from the official website:

mkdir -p /var/www/html/nextcloud
cd /var/www/html/nextcloud

Extract the archive:

tar xvf latest.tar.bz2

Create a directory to store Nextcloud data:

mkdir -p /var/www/html/nextcloud/data

Make the web server the owner of the data directory:

chown -R www-data:www-data /var/www/html/nextcloud/

Step 6. Set Up Apache Virtual Host.

We need to create a virtual host configuration file for Nextcloud:

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

Add the following content, replacing [your_domain] with your domain name or IP address:

<VirtualHost *:80>
ServerAdmin admin@[your_domain]
DocumentRoot /var/www/html/nextcloud
ServerName [your_domain]

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /var/www/html/nextcloud/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
SetEnv HOME /var/www/html/nextcloud
SetEnv HTTP_HOME /var/www/html/nextcloud

Enable the virtual host you just created:

a2ensite nextcloud.conf

Next, modify the default Apache configuration to ensure compatibility with Nextcloud:

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

Add the following lines:

<Directory /var/www/html/nextcloud/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
SetEnv HOME /var/www/html/nextcloud
SetEnv HTTP_HOME /var/www/html/nextcloud

Save and exit the file. Restart Apache for the changes to take effect:

sudo systemctl restart apache2

Step 7. Secure Nextcloud with Let’s Encrypt SSL.

Certbot is a tool that simplifies the process of obtaining and renewing SSL certificates. Install Certbot and the Apache plugin:

sudo apt install certbot python3-certbot-apache

Run Certbot to obtain and install the SSL certificate:

certbot --apache

Step 8. Access Nextcloud via the Web Browser.

Open your web browser and navigate to https://[your_domain]. You’ll see the Nextcloud setup page.

Install Nextcloud on Debian 12 Bookworm

Congratulations! You have successfully installed Nextcloud. Thanks for using this tutorial to install the latest version of Nextcloud on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Nextcloud website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!
Back to top button