Desert Forge IT — Arizona IT · Field-tested tools & guidesFree consult →

How to Self-Host Nextcloud on Debian/Ubuntu

Intermediate 40 min — Set up your own cloud storage with Nextcloud.

Overview

Nextcloud is a self-hosted cloud storage platform — your own Dropbox/Google Drive. File sync, sharing, calendar, contacts, and apps. This guide covers installation on Debian 12 with Apache, MariaDB, and Let's Encrypt.

Prerequisites

  • Debian 12 or Ubuntu 22.04 server
  • A domain name pointing to your server
  • Root access

Install LAMP Stack

apt update && apt install -y apache2 mariadb-server \
  php8.2 php8.2-gd php8.2-mysql php8.2-curl php8.2-mbstring \
  php8.2-intl php8.2-gmp php8.2-bcmath php8.2-xml php8.2-zip \
  php8.2-imagick php8.2-apcu libapache2-mod-php8.2

Create Database

mysql -u root << 'EOF'
CREATE DATABASE nextcloud;
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;
EOF

Download Nextcloud

cd /var/www
wget https://download.nextcloud.com/server/releases/latest.tar.bz2
tar xjf latest.tar.bz2
chown -R www-data:www-data /var/www/nextcloud
rm latest.tar.bz2

Apache Configuration


  ServerName cloud.yourdomain.com
  DocumentRoot /var/www/nextcloud

  
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
  

Enable the config:

a2ensite nextcloud.conf
a2enmod rewrite headers env dir mime
systemctl restart apache2

SSL with Certbot

apt install -y certbot python3-certbot-apache
certbot --apache -d cloud.yourdomain.com

Run Web Installer

Visit https://cloud.yourdomain.com in your browser. Enter:

  • Admin username and password
  • Data folder: /var/www/nextcloud/data
  • Database: MySQL/MariaDB
  • Database user: nextcloud
  • Database password: your_strong_password
  • Database name: nextcloud
  • Host: localhost

Performance Tuning

# /var/www/nextcloud/config/config.php — add:
'memcache.local' => '\OC\Memcache\APCu',
'default_phone_region' => 'US',

Also increase PHP memory limit:

sed -i 's/memory_limit = 128M/memory_limit = 512M/' /etc/php/8.2/apache2/php.ini
systemctl restart apache2

Background Jobs

crontab -u www-data -e
# Add:
*/5 * * * * php /var/www/nextcloud/cron.php

Then in Nextcloud Settings → Administration → Basic settings, select 'Cron' for background jobs.

← Back to Knowledge Base