docs / https / nextcloud-server-installation-guide-for-debian-12-root-user
Nextcloud Server Installation Guide for Debian 12 (Root User)
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:
apt update
apt upgrade -yThe 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:
apt install curl unzip -yStep 2: Install and Configure Apache2 Web Server
nstall Apache2
apt install apache2 -yEnable Apache2 Service Startup
Configure Apache2 to start automatically when the system boots:
systemctl enable apache2
systemctl start apache2Verify Apache2 Status
Confirm that Apache2 is running:
systemctl status apache2You should see output indicating active (running).
Enable Required Apache2 Modules
Nextcloud requires several Apache2 modules to function properly. Enable them one by one:
# 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_shmcbAfter enabling modules, restart Apache2 to apply the changes:
systemctl restart apache2Step 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:
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- 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:
php --version
php -mYou 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:
nano /etc/php/8.2/apache2/php.iniWithin 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:
date.timezone = UTCYou 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):
memory_limit = 512M
upload_max_filesize = 500M
post_max_size = 600M
max_execution_time = 300These 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
file_uploads = On
allow_url_fopen = On4. Disable Error Display (Security)
display_errors = Off
output_buffering = Off5. Enable and Configure OPcache
Find the line with zend_extension= (around line 908). Uncomment and set it to:
zend_extension=opcacheThen locate the [opcache] section (near end of file) and add/modify these settings:
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- 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
systemctl restart apache2Step 4: Install and Configure MariaDB Database Server
Install MariaDB
apt install mariadb-server -yEnable and Start MariaDB
systemctl enable mariadb
systemctl start mariadbVerify MariaDB Status
systemctl status mariadbSecure Your MariaDB Installation
Run the security hardening script:
mariadb-secure-installationDuring 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:
mariadb -u root -pWhen prompted, enter the root password. You’ll see the MariaDB [(none)]> prompt.
Run these commands to create a database and restricted user for Nextcloud:
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:
SHOW GRANTS FOR 'nextclouduser'@'localhost';You should see GRANT statements for the nextcloud_db database.
Exit MariaDB:
quitStep 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
unzip nextcloud.zipChange ownership to the Apache2 user (www-data) so Apache can access and modify files:
chown -R www-data:www-data /var/www/nextcloudVerify the extraction:
ls -la /var/www/nextcloud/ | head -20You 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:
nano /etc/apache2/sites-available/nextcloud.confPaste this configuration, replacing example domain with your actual domain (cloud.domain.com):
<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 verificationDocumentRoot: Path to Nextcloud filesErrorLog/CustomLog: Log file paths (created automatically)AllowOverride All: Allows.htaccessrewriting (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
a2ensite nextcloud.confVerify Apache Configuration Syntax
apachectl configtestYou should see: Syntax OK
If you see errors, re-check your configuration file for typos.
Restart Apache
systemctl restart apache2Step 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:
apt install snapd -yInstall Certbot via Snap
snap install --classic certbotCreate Symlink for Easy Access
ln -s /snap/bin/certbot /usr/bin/certbotVerify installation:
certbot --versionGenerate SSL Certificate and Configure Apache Automatically
This single command will:
- Contact Let’s Encrypt servers
- Validate domain ownership
- Generate SSL certificate
- Automatically modify your Apache configuration
- Set up HTTPS redirect
Replace cloud.telumglobal.com and email with your actual domain and email address:
certbot --apache --agree-tos --redirect --hsts --staple-ocsp \
--email admin@domain.com -d cloud.domain.com--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:
- Email for notifications: Use your email (already provided in command)
- Share email with EFF: Answer
YorN(optional)
Verify SSL Certificate
After successful completion, verify your certificate installation:
ls -la /etc/letsencrypt/live/cloud.domain.com/You should see:
cert.pem: Your SSL certificateprivkey.pem: Your private keychain.pem: Certificate chain
Configure Automatic Certificate Renewal
Let’s Encrypt certificates expire after 90 days. Certbot automatically sets up renewal via systemd timer. Verify:
systemctl list-timers | grep certbotTest renewal (dry-run, doesn’t actually renew):
certbot renew --dry-runStep 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:
chown -R www-data:www-data /var/www/nextcloud
chmod -R 755 /var/www/nextcloudAccess Installation Wizard
Open a web browser and navigate to:
https://cloud.domain.comNote: 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(or127.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:
- Create database tables
- Generate configuration files
- Initialize Nextcloud system
- 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:
nano /var/www/nextcloud/config/config.phpFind the $CONFIG = array ( section and add the following line after existing entries:
'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:
crontab -u www-data -eThis opens the crontab editor. If prompted, select nano. Add this single line at the end:
*/5 * * * * php -f /var/www/nextcloud/cron.phpThis runs Nextcloud background jobs every 5 minutes.
Save and exit: Ctrl+O, Enter, Ctrl+X.
Verify Cron Configuration
crontab -u www-data -lYou 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:
nano /var/www/nextcloud/config/config.phpFind or add this configuration (inside the $CONFIG array):
'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.
Step 10: Security Hardening (Optional but Recommended)
Configure UFW Firewall
Install the Uncomplicated Firewall (UFW):
apt install ufw -yEnable firewall and allow only essential services:
ufw allow OpenSSH
ufw allow "WWW Full" # Allows both HTTP (80) and HTTPS (443)
ufw enableConfirm with y when prompted.
Check Firewall Status
ufw statusYou should see:
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
WWW Full ALLOW AnywhereVerify 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 greenHTTPS 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:
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:
certbot renew -vCheck error messages. Ensure domain DNS A record points to server IP.
500 Error / PHP Errors
Cause: Permission or module issues.
Fix:
# 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 apache2Certbot Port 80 Already in Use
Cause: Another service using port 80.
Fix: Use --apache plugin (which uses port 443 for standalone challenges):
certbot certonly --apache -d cloud.domain.comAdditional Resources
- [Nextcloud Official Admin Manual]
- Apache2 Security Configuration
- Let’s Encrypt Documentation
- MariaDB Security Guidelines
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.