docs / https / nextcloud-server-installation-guide-for-debian-12-root-user

Nextcloud Server Installation Guide for Debian 12 (Root User)

https updated 2026-01-03

This guide provides detailed step-by-step instructions for installing Nextcloud Server on a fresh Debian 12 VM running as root, with Apache2, MariaDB, and SSL/TLS encryption via Let’s Encrypt.

System Requirements and Prerequisites

Your installation requires the following:

  • Fresh Debian 12 (Bookworm) VM with root access
  • Minimum 4GB RAM and 2 CPUs (recommended for optimal performance)​
  • Domain name configured: cloud.telumglobal.com (must point to your server’s IP address)
  • Internet connectivity for package downloads and Let’s Encrypt certificate validation

Step 1: System Preparation

Before installing any packages, update your system’s package index and ensure all installed packages are current:

textcopy
apt update
apt upgrade -y

The apt update command refreshes the package list, while apt upgrade installs security patches and updates for all currently installed packages.

Install Essential Tools

Install curl and unzip, which are required for downloading and extracting the Nextcloud source code:

textcopy
apt install curl unzip -y

Step 2: Install and Configure Apache2 Web Server

nstall Apache2

textcopy
apt install apache2 -y

Enable Apache2 Service Startup

Configure Apache2 to start automatically when the system boots:

textcopy
systemctl enable apache2
systemctl start apache2

Verify Apache2 Status

Confirm that Apache2 is running:

textcopy
systemctl status apache2

You should see output indicating active (running).

Enable Required Apache2 Modules

Nextcloud requires several Apache2 modules to function properly. Enable them one by one:​

textcopy
# REQUIRED module for URL rewriting (used by Nextcloud)
a2enmod rewrite

# RECOMMENDED modules for optimal functionality
a2enmod headers
a2enmod env
a2enmod dir
a2enmod mime

# REQUIRED for HTTPS/SSL support
a2enmod ssl
a2enmod socache_shmcb

After enabling modules, restart Apache2 to apply the changes:

textcopy
systemctl restart apache2

Step 3: Install and Configure PHP 8.2

Install PHP and Required Extensions

Debian 12 includes PHP 8.2 in its default repositories, which is the recommended version for Nextcloud. Install PHP and all required extensions in a single command:​

textcopy
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-mbstring \
  php-zip \
  php-soap \
  php-bz2 \
  php-bcmath \
  php-gmp \
  php-apcu \
  libmagickcore-dev

These extensions provide:​

  • curl: HTTP requests and external connections
  • mysql: Database connectivity (via PDO)
  • gd: Image manipulation and thumbnail generation
  • xml, json: Data format handling
  • intl: Multi-language support
  • imagick: Advanced image previews
  • mbstring: Multi-byte character support
  • zip: Compressed file handling
  • soap, bz2, bcmath, gmp: Additional functionality
  • apcu: In-memory caching for performance

Verify PHP Installation

Check that PHP 8.2 is installed and list all active modules:

textcopy
php --version
php -m

You should see PHP 8.2.x and modules including gd, mysql, imagick, xml, and zip.

Configure PHP for Nextcloud

Edit the PHP configuration file for Apache2:

textcopy
nano /etc/php/8.2/apache2/php.ini

Within this file, locate and modify the following parameters. Use Ctrl+W in nano to search for each parameter:

1. Set Timezone

Find date.timezone = (around line 985) and uncomment/modify it:

textcopy
date.timezone = UTC

You can use any valid timezone. Common options include Europe/Amsterdam, America/New_York, Asia/Tokyo.

2. Increase Memory and Upload Limits

Find and modify these parameters (search for each one):

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

These values allow:

  • 512M memory: PHP script execution headroom
  • 500M upload: Maximum single file upload size
  • 600M post_max_size: Total POST data allowed (must exceed upload_max_filesize)
  • 300 seconds: Timeout for long-running operations

3. Enable File Operations

textcopy
file_uploads = On
allow_url_fopen = On

4. Disable Error Display (Security)

textcopy
display_errors = Off
output_buffering = Off

5. Enable and Configure OPcache

Find the line with zend_extension= (around line 908). Uncomment and set it to:

textcopy
zend_extension=opcache

Then locate the [opcache] section (near end of file) and add/modify these settings:​

textcopy
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

These OPcache settings:​

  • enable = 1: Activates bytecode caching
  • interned_strings_buffer = 8: Memory for string interning (MB)
  • max_accelerated_files = 10000: Maximum cached files
  • memory_consumption = 128: OPcache memory allocation (MB)
  • save_comments = 1: Preserves PHP comments (needed by some apps)
  • revalidate_freq = 1: Check files every second for changes

Save and exit: Press Ctrl+O, then Enter, then Ctrl+X.

Restart Apache2 to Apply PHP Configuration

textcopy
systemctl restart apache2

Step 4: Install and Configure MariaDB Database Server

Install MariaDB

textcopy
apt install mariadb-server -y

Enable and Start MariaDB

textcopy
systemctl enable mariadb
systemctl start mariadb

Verify MariaDB Status

textcopy
systemctl status mariadb

Secure Your MariaDB Installation

Run the security hardening script:

textcopy
mariadb-secure-installation

During this interactive process, follow these recommended responses:

PromptResponseReasonEnter current root passwordPress ENTERDefault is no password initiallySwitch to unix_socket authentication?nKeep traditional password authChange root password?YSet a strong passwordRemove anonymous users?YDisable default accountsDisable remote root login?YSecurity (root only via socket)Remove test database?YRemove default test databaseReload privilege tables?YApply all security changes

Important: Write down the root password you set—you’ll need it when creating the Nextcloud database.

Create Nextcloud Database and User

Log into MariaDB with the root password you just set:

textcopy
mariadb -u root -p

When prompted, enter the root password. You’ll see the MariaDB [(none)]> prompt.

Run these commands to create a database and restricted user for Nextcloud:​

textcopy
CREATE DATABASE nextcloud_db;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON nextcloud_db.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;

IMPORTANT: Replace StrongPassword123! with a strong, unique password. Store this securely—you’ll need it during the Nextcloud installation wizard.

Verify the user has access:

textcopy
SHOW GRANTS FOR 'nextclouduser'@'localhost';

You should see GRANT statements for the nextcloud_db database.

Exit MariaDB:

textcopy
quit

Step 5: Download and Extract Nextcloud

Create Nextcloud Directory

Navigate to the web root and download Nextcloud:cd /var/wwwcurl -o nextcloud.zip https://download.nextcloud.com/server/releases/latest.zip

This downloads the latest stable Nextcloud version.

Extract and Set Permissions

textcopy
unzip nextcloud.zip

Change ownership to the Apache2 user (www-data) so Apache can access and modify files:

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

Verify the extraction:

textcopy
ls -la /var/www/nextcloud/ | head -20

You should see directories like apps, config, core, and files like index.php, occ.


Step 6: Configure Apache Virtual Host

Create an Apache virtual host configuration file for your Nextcloud domain:

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

Paste this configuration, replacing example domain with your actual domain (cloud.domain.com):

textcopy
<VirtualHost *:80>
    ServerName cloud.domain.com
    DocumentRoot /var/www/nextcloud/

    # Log files
    ErrorLog /var/log/apache2/cloud.domain.com-error.log
    CustomLog /var/log/apache2/cloud.domain.com-access.log combined

    <Directory /var/www/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted

        <IfModule mod_dav.c>
            Dav off
        </IfModule>

        SetEnv HOME /var/www/nextcloud
        SetEnv HTTP_HOME /var/www/nextcloud
    </Directory>
</VirtualHost>

Configuration details:

  • ServerName: Your domain name for certificate verification
  • DocumentRoot: Path to Nextcloud files
  • ErrorLog/CustomLog: Log file paths (created automatically)
  • AllowOverride All: Allows .htaccess rewriting (required by Nextcloud)
  • Dav off: Disables WebDAV module conflicts (Nextcloud has its own WebDAV)
  • SetEnv: Sets environment variables for Nextcloud

Save and exit: Ctrl+O, Enter, Ctrl+X.

Enable the Virtual Host

textcopy
a2ensite nextcloud.conf

Verify Apache Configuration Syntax

textcopy
apachectl configtest

You should see: Syntax OK

If you see errors, re-check your configuration file for typos.

Restart Apache

textcopy
systemctl restart apache2

Step 7: Install and Configure Certbot for HTTPS/SSL

Before proceeding, ensure your domain (cloud.domain.com) is pointing to your server’s public IP address. SSL certificate validation will fail otherwise.

Install Snapd (Required for Modern Certbot)

While Debian provides a Certbot package via apt, the snap version is recommended for automatic updates. Install snapd:

textcopy
apt install snapd -y

Install Certbot via Snap

textcopy
snap install --classic certbot
textcopy
ln -s /snap/bin/certbot /usr/bin/certbot

Verify installation:

textcopy
certbot --version

Generate SSL Certificate and Configure Apache Automatically

This single command will:

  1. Contact Let’s Encrypt servers
  2. Validate domain ownership
  3. Generate SSL certificate
  4. Automatically modify your Apache configuration
  5. Set up HTTPS redirect

Replace cloud.telumglobal.com and email with your actual domain and email address:

textcopy
certbot --apache --agree-tos --redirect --hsts --staple-ocsp \
  --email admin@domain.com -d cloud.domain.com

Parameter explanations:​

  • --apache: Automatically configure Apache for HTTPS
  • --agree-tos: Accept Let’s Encrypt terms automatically
  • --redirect: Redirect all HTTP traffic to HTTPS
  • --hsts: Add HSTS header for maximum security
  • --staple-ocsp: Staple OCSP responses (improves security)
  • --email: Email for certificate expiration notifications
  • -d: Domain name to certificate

Interactive Prompts

During execution, Certbot may ask:

  1. Email for notifications: Use your email (already provided in command)
  2. Share email with EFF: Answer Y or N (optional)

Verify SSL Certificate

After successful completion, verify your certificate installation:

textcopy
ls -la /etc/letsencrypt/live/cloud.domain.com/

You should see:

  • cert.pem: Your SSL certificate
  • privkey.pem: Your private key
  • chain.pem: Certificate chain

Configure Automatic Certificate Renewal

Let’s Encrypt certificates expire after 90 days. Certbot automatically sets up renewal via systemd timer. Verify:

textcopy
systemctl list-timers | grep certbot

Test renewal (dry-run, doesn’t actually renew):

textcopy
certbot renew --dry-run

Step 8: Complete Nextcloud Installation via Web Interface

Fix Directory Permissions

Change Nextcloud directory ownership to www-data to allow the installer to write configuration files:

textcopy
chown -R www-data:www-data /var/www/nextcloud
chmod -R 755 /var/www/nextcloud

Access Installation Wizard

Open a web browser and navigate to:

textcopy
https://cloud.domain.com

Note: It must be HTTPS (not HTTP) due to the automatic redirect you configured.

If you see a security warning, it’s normal for self-validating certificates. Click “Advanced” and “Proceed to site”.

Complete Installation Form

You’ll see the Nextcloud installation wizard. Fill in the following:

Administrator Account

  • Username: Your desired Nextcloud admin username (e.g., admin)
  • Password: Create a strong admin password

Data Directory (Optional)

Leave as default: /var/www/nextcloud/data (or specify a separate partition for better performance)

Database Configuration

  • Database type: Select MySQL/MariaDB
  • Database name: nextcloud_db (from Step 4)
  • Database user: nextclouduser (from Step 4)
  • Database password: Enter the password you set in Step 4
  • Database host: localhost (or 127.0.0.1)

Apps

You can uncheck “Install recommended apps” if you want to minimize initial setup time. Install apps later from the admin panel.

Click “Finish Setup”

The installer will:

  1. Create database tables
  2. Generate configuration files
  3. Initialize Nextcloud system
  4. Redirect to the login page

This may take 1-3 minutes depending on your server specs.

Login

Use the administrator credentials you created to log in.


Step 9: Post-Installation Configuration and Performance Tuning

Enable Memory Caching

Edit Nextcloud’s configuration file:

textcopy
nano /var/www/nextcloud/config/config.php

Find the $CONFIG = array ( section and add the following line after existing entries:

textcopy
'memcache.local' => '\OC\Memcache\APCu',

This enables APCu for local caching, which significantly improves performance.​

Save and exit: Ctrl+O, Enter, Ctrl+X.

Set Up Background Jobs (Cron)

Nextcloud performs maintenance tasks via cron jobs. Configure cron execution:

textcopy
crontab -u www-data -e

This opens the crontab editor. If prompted, select nano. Add this single line at the end:

textcopy
*/5 * * * * php -f /var/www/nextcloud/cron.php

This runs Nextcloud background jobs every 5 minutes.

Save and exit: Ctrl+O, Enter, Ctrl+X.

Verify Cron Configuration

textcopy
crontab -u www-data -l

You should see your cron entry listed.

Configure Trusted Domains (If Accessing from Multiple IPs)

If users will access Nextcloud from different domains or IP addresses, add them to the trusted domains configuration:

bashcopy
nano /var/www/nextcloud/config/config.php

Find or add this configuration (inside the $CONFIG array):

textcopy
'trusted_domains' => array (
    0 => 'localhost',
    1 => '127.0.0.1',
    2 => 'cloud.telumglobal.com',
    3 => 'your-ip-address',
),

Replace your-ip-address with your server’s actual public IP if needed.


Configure UFW Firewall

Install the Uncomplicated Firewall (UFW):

textcopy
apt install ufw -y

Enable firewall and allow only essential services:

textcopy
ufw allow OpenSSH
ufw allow "WWW Full"  # Allows both HTTP (80) and HTTPS (443)
ufw enable

Confirm with y when prompted.

Check Firewall Status

textcopy
ufw status

You should see:

textcopy
Status: active

     To                         Action      From
     --                         ------      ----
OpenSSH                    ALLOW       Anywhere
WWW Full                   ALLOW       Anywhere

Verify Nextcloud Admin Panel

Log into Nextcloud as admin and navigate to Administration Settings → Overview.

You should see a green checkmark next to most security settings. Address any warnings:

  • PHP OPcache module loaded: Should be green (if not, restart Apache)
  • PHP Imagick module loaded: Should be green
  • HTTPS enabled: Should be green (Let’s Encrypt)

Verification Checklist

Before declaring installation complete, verify:

ComponentVerification CommandExpected ResultApache2systemctl status apache2``active (running)MariaDBsystemctl status mariadb``active (running)PHPphp --versionPHP 8.2.xNextcloud AccessVisit https://cloud.domain.comNextcloud login page loadsSSL CertificateVisit and check browser lockGreen lock icon, valid certificateDatabaseLogin → Admin → System InformationDatabase connection shows “ok”Memory CacheAdmin → System InformationAPCu shows as availableBackground JobsAdmin → OverviewBackground jobs running via Cron


Troubleshooting Common Issues

Apache Shows Debian Default Page Instead of Nextcloud

Cause: Default Apache site is still enabled.

Fix:

textcopy
a2dissite 000-default.conf
systemctl reload apache2

“Untrusted Domain” Error

Cause: Accessing Nextcloud via IP or domain not in trusted_domains list.

Fix: Add domain to /var/www/nextcloud/config/config.php in the trusted_domains array (see Step 9).

Certificate Renewal Fails

Cause: Domain DNS not pointing to server.

Fix:

textcopy
certbot renew -v

Check error messages. Ensure domain DNS A record points to server IP.

500 Error / PHP Errors

Cause: Permission or module issues.

Fix:

textcopy
# Fix permissions
chown -R www-data:www-data /var/www/nextcloud

# Check PHP modules
php -m | grep -E "curl|gd|mysql|xml|zip"

# Restart Apache
systemctl restart apache2

Certbot Port 80 Already in Use

Cause: Another service using port 80.

Fix: Use --apache plugin (which uses port 443 for standalone challenges):

textcopy
certbot certonly --apache -d cloud.domain.com

Additional Resources


Installation Summary: You’ve successfully deployed Nextcloud with:

  • ✅ Apache2 web server with required modules
  • ✅ PHP 8.2 with OPcache and APCu caching
  • ✅ MariaDB database with restricted user
  • ✅ HTTPS/SSL via Let’s Encrypt with automatic renewal
  • ✅ Firewall protection (UFW)
  • ✅ Background job automation (cron)
  • ✅ Performance optimization (memory caching, OPcache)

Your Nextcloud instance is now ready for production use.