• Self-Host Nextcloud on Debian: The Ultimate Step-by-Step Build Guide

    Set up your own Nextcloud server on Debian β€” from scratch! In this step-by-step tutorial, I’ll walk you through the complete installation process, including server preparation, database setup, Apache configuration, PHP tuning, performance tweaks, securing your cloud with Let’s Encrypt (and more). Whether you’re hosting files for personal use, your business, or a homelab, this guide covers everything you need to build a fast, secure, and reliable Nextcloud instance.

    You’ll learn how to create a cloud server, configure MariaDB, optimize PHP settings, fix missing indices, enable Redis for speed, and properly secure your deployment. No skipped steps β€” just a full, detailed setup walkthrough you can follow with confidence.

    YouTube player
    Read more: Self-Host Nextcloud on Debian: The Ultimate Step-by-Step Build Guide

    Video Notes

    The following sections contain notes, commands, and config files that were used during this video.

    What you’ll need

    To have the best experience, you’ll need the following:

    A Linux server

    You’ll need a Linux server for this project. You can use a physical server, virtual machine, or cloud instance. In the video, a Linode instance is used on Akamai’s cloud platform. If you want to follow along exactly, you’ll need to create a Linode instance. Otherwise, you can “translate” what’s being done in the video to your chosen platform.

    Also, Debian 13 “Trixie” is used for the build within the video. Nextcloud can be set up on just about any distribution, but if you don’t choose Debian, then you’ll have to search for alternatives for some of the steps as package names and individual commands change per distro.

    Note: This video was NOT sponsored by Akamai/Linode (or anyone else for that matter). While Linode has sponsored Learn Linux TV in the past, they are not currently a sponsor. Linode was chosen only because I already have an account on the platform.

    Domain name

    While you can use Nextcloud without a domain name, it’s highly recommended that you use one. You can use your favorite domain registrar to register a domain if you don’t already have one.

    Note: After you create your Debian server, be sure to add its IP address to your DNS provider to ensure your instance is reachable by its name.

    Randomly Generated passwords

    Feel free to generate some random passwords ahead of time to use for your build. You’ll need a randomly generated password for each of the following:

    • Debian root user
    • MariaDB root user
    • Nextcloud database
    • Nextcloud admin user

    Install updates

    The first thing you should do is install all available updates, and it’s important to always do this once you set up any Linux server for the first time.

    First, update the package repository index:

    apt update

    Once that’s done, install any updates that might be available:

    apt dist-upgrade

    Update hostname

    Next, update the hostname of your Linux server to reflect the domain name you decided to use for your build. The fully qualified domain name that was used in the video was nc.learnlinux.cloud (which was used only for the recording, it doesn’t exist now – just replace it with yours).

    Update the /etc/hostname file to reflect your chosen name:

    nano /etc/hostname

    Also, update the /etc/hosts file to reflect your chosen name:

    nano /etc/hosts

    For example, you might add an entry that looks similar to this:

    127.0.1.1  nc.learnlinux.cloud  nc

    Create a non-root user

    If you don’t already have a standard user account, be sure to add one (it’s not a good idea to continually use the root account). The following command was used to create user jay within the video:

    adduser jay

    Next, add your user to the sudo group to ensure you can run privileged commands:

    usermod -aG sudo jay

    Note: Be sure to replace jay with your chosen username.

    Reboot

    Reboot the server so that it takes advantage of all of the updates:

    sudo reboot

    Set up MariaDB

    For this build, MariaDB was used to provide the required database layer.

    Install MariaDB:

    To install MariaDB, run the following command:

    sudo apt install mariadb-server mariadb-client-compat

    Check the status:

    Run the following command to ensure MariaDB is running:

    systemctl status mariadb

    If it’s not, use the following command which will ensure it’s running and also enabled (meaning it will start at boot):

    sudo systemctl enable --now mariadb

    Implement basic security:

    Since MariaDB is a big target for threat actors, we need to secure it. The following command will prompt you for various things to provide minimum security:

    sudo mysql_secure_installation

    Create a database for Nextcloud:

    Next, we’ll create the actual database that Nextcloud will end up using. To create it, enter the MariaDB shell:

    sudo mariadb

    Then, create the database:

    CREATE DATABASE nextcloud;

    Make sure it was actually created (it should appear in the list):

    SHOW DATABASES;

    Next, we’ll need to ensure Nextcloud will have access to its database. The following command will create a “user grant” that Nextcloud will use:

    GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost' IDENTIFIED BY 'mypassword';

    Finally, exit the MariaDB shell to return back to the normal command prompt:

    exit

    Install Apache

    For this build, Apache will serve as the web server for Nextcloud. Install these packages (Apache will be installed automatically as a dependency):

    sudo apt install imagemagick-7.q16 php php-apcu php-bcmath php-cli php-common php-curl php-gd php-gmp php-imagick php-intl php-mbstring php-mysql php-zip php-xml

    Check to make sure Apache is running:

    systemctl status apache2

    Test Apache

    Visit your URL in your browser to make sure the default page loads, you should see the default Apache start page,

    Install Nextcloud

    At this point, we’ll install some additional dependencies and then copy Nextcloud’s files to the server.

    Install required packages:

    The following packages are required for Apache to be able to serve Nextcloud properly:

    sudo phpenmod apcu bcmath gmp imagick intl unzip

    Download Nextcloud:

    Next, download Nextcloud’s latest release file to the server (requires the wget package be installed):

    wget https://download.nextcloud.com/server/releases/latest.zip

    Unzip Nextcloud:

    We’ll need to use the unzip comand to extract files from the downloaded archive (the unzip package will need to be installed for this to work):

    unzip latest.zip

    Remove the Nextcloud zip file:

    We won’t need latest.zip anymore, so feel free to remove it if you don’t plan on using it again:

    rm latest.zip

    Move the Nextcloud directory to the appropriate place:

    Rename the extracted Nextcloud directory to match your server’s FQDN (optional but recommended):

    mv nextcloud nc.learnlinux.cloud

    Change ownership for the Nextcloud directory so that Apache will have access to it:

    sudo chown -R www-data:www-data nc.learnlinux.cloud


    Next, move your Nextcloud directory into the /var/www directory:

    sudo mv nc.learnlinux.cloud /var/www/

    Disable the default Apache site:

    Next, you can disable the default Apache start page since we won’t be needing it:

    sudo a2dissite 000-default.conf

    Apache Virtual Host Configuration

    Next, we’ll create a config file that will instruct Apache how to serve Nextcloud.

    Create the config file:

    sudo nano /etc/apache2/sites-available/nc.learnlinux.cloud.conf

    Add the following to the file:

    <VirtualHost *:80>
    DocumentRoot "/var/www/nc.learnlinux.cloud"
    ServerName nc.learnlinux.cloud

    <Directory "/var/www/nc.learnlinux.cloud/">
    Options MultiViews FollowSymlinks
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>

    TransferLog /var/log/apache2/nc.learnlinux.cloud_access.log
    ErrorLog /var/log/apache2/nc.learnlinux.cloud_error.log

    </VirtualHost>

    Enable the new config file:

    sudo a2ensite nc.learnlinux.cloud.conf

    Set PHP settings

    Edit the PHP config file so we can adjust some settings:

    sudo nano /etc/php/8.4/apache2/php.ini

    Set the following parameters:

    memory_limit = 512M
    upload_max_filesize = 200M
    max_execution_time = 360
    post_max_size = 200M
    date.timezone = America/Detroit
    opcache.enable=1
    opcache.interned_strings_buffer=16
    opcache.max_accelerated_files=10000
    opcache.memory_consumption=128
    opcache.save_comments=1
    opcache.revalidate_freq=1

    Enable required modules for Apache:

    sudo a2enmod dir env headers mime rewrite ssl

    Enable Caching:

    Open the apcu.ini file in an editor:

    sudo nano /etc/php/8.4/mods-available/apcu.ini

    Add the following to the end of the file:

    apc.enable_cli=1

    Restart Apache to apply our changes so far:

    sudo systemctl restart apache2

    Set up Nextcloud

    To apply the initial configuration, visit your Nextcloud site and answer the questions. You’ll be asked for a password for the admin user, database name, and database password. Add that information, and Nextcloud will be installed!

    Post Install: Tweak Nextcloud Database

    Although we just ran through the installer, there’s a few things Nextcloud doesn’t do on a fresh install. To implement these tweaks, first mark the occ script executable (be sure to update the path to match yours):

    sudo chmod +x /var/www/nc.learnlinux.cloud/occ

    Run the following command to add missing databases indices:

    sudo /var/www/nc.learnlinux.cloud/occ db:add-missing-indices

    Update mimetypes as well:

    sudo /var/www/nc.learnlinux.cloud/occ maintenance:repair --include-expensive

    Remove execution bit from occ to increase security:

    sudo chmod -x /var/www/nc.learnlinux.cloud/occ

    Post Install: Update config file permissions

    The following commands will increase security for the config file:

    Set ownership:

    sudo chown root:www-data /var/www/nc.learnlinux.cloud/config/config.php

    Set permissions:

    sudo chmod 660 /var/www/nc.learnlinux.cloud/config/config.php

    Post Install: Enable Caching

    To enable caching, first edit the Nextcloud config file:

    sudo nano /var/www/nc.learnlinux.cloud/config/config.php

    Add to the file:

    'memcache.local' => '\\OC\\Memcache\\APCu',
    'default_phone_region' => 'US',

    Post Install: Set up Let’s Encrypt

    To set up a certificate for encryption, we’ll first install Certbot:

    sudo apt install python3-certbot-apache

    Apply a certificate to your site:

    sudo certbot --apache -d nc.learnlinux.cloud

    To fully benefit from our certificate, enable strict transport security:

    sudo nano /etc/apache2/sites-available/nc.learnlinux.cloud-le-ssl.conf

    Add to the config file:

    <IfModule mod_headers.c>
    Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
    </IfModule>

    Post Install: : Install Redis

    Redis is optional, but can add performance benefits. To install it:

    sudo apt install redis-server php-redis

    Edit the Redis config file:

    sudo nano /etc/redis/redis.conf

    change: Port 6379 to 0

    Uncomment: unixsocket /run/redis/redis-server.sock

    Uncomment: unixsocketperm 700 (change to 770)

    Add the www-data user to the redis group:

    sudo usermod -aG redis www-data

    Edit the Nextcloud config file to use Redis:

    sudo vim /var/www/nc.learnlinux.cloud/config/config.php

    Add the following to the file:

      'filelocking.enabled' => true,
    'memcache.locking' => '\\OC\\Memcache\\Redis',
    'redis' =>
    array(
    'host' => '/var/run/redis/redis-server.sock',
    'port' => 0,
    'timeout' => 0.0,
    ),

    Restart Apache to apply our final changes:

    sudo systemctl restart apache2
  • Change Your Desktop Environment in Debian – Complete Guide

    Want to change the look and feel of your Debian system? In this video, you’ll learn step-by-step how to switch desktop environments in Debian, whether you’re setting up Debian for the first time or customizing an existing installation. I’ll walk you through choosing a desktop environment during installation, adding or removing desktops later with “tasksel”, selecting the right display manager (GDM, SDDM, or LightDM), and how to switch between desktop environments right from the login screen.

    Whether you prefer GNOME, KDE Plasma, XFCE, Cinnamon, or another desktop environment, this tutorial will help you install, switch, and customize Debian to match your workflow.

    YouTube player
  • Debian 13 (Trixie) Review – What’s New, Installation & Upgrade Overview

    Debian 13 β€œTrixie” is here! In this full review, I take a close look at the latest Debian release, covering what’s new in Debian 13, upgrade considerations, and the pros and cons you should know before you decide whether to move from Debian 12.

    In this video, you’ll learn about the updated software stack, the installation and upgrade process, and my thoughts on where Debian 13 shines β€” and where it still falls short. Whether you’re a long-time Debian user or just curious about trying one of the most stable Linux distributions, this review will give you the insights you need.

    YouTube player
  • Which Linux Mint is Better? Comparing Debian Edition & Standard

    Linux Mint Debian Edition (LMDE) is a very interesting distribution to say the least. It looks and acts nearly exactly the same as the standard version of Linux Mint, but LMDE is built on top of Debian instead of Ubuntu. In this video, Jay compares LMDE to the flagship edition of Linux Mint and also gives it an updated review.

    YouTube player
  • How I Set Up the Sway Window Manager on Debian 12

    Recently, I mentioned that I was switching each of my Linux installs to Debian. But what does that mean for my laptops and desktops? In this video, I’ll show you the Sway window manager implementation I’ve been working on, and where it stands as of now. Plus, I’ll show you how you can set this up for yourself!

    YouTube player

    Thanks to Akamai for sponsoring this video! Check out Akamai’s cloud platform to spin up your very own Linux server!

    (more…)
  • Beginner’s Guide for Navigating the Debian 12 “Bookworm” Live Installer

    Debian 12, codenamed “Bookworm” was released earlier this year – and it’s one of the greatest Linux distribution releases in some time. In this video, Jay shows off the “Live” installer for the latest Debian Stable, complete with a walkthrough of the installation process.

    YouTube player

    Thanks to Akamai for sponsoring this video! Check out their cloud offering and spin up your very own Linux server!

  • The Homelab Show Episode 100 – Debian 12 “Bookworm” is Awesome (Featuring Veronica from Veronica Explains)

    Debian 12 is awesome! But you probably already knew that, especially from the excitement over this latest release of the popular stable Linux distribution. However, Debian 12 is not just awesome, it’s the best release in the distro’s three-decade history! In this video, Jay and Tom are joined by Veronica from Veronica Explains to chat about this awesome release.

    YouTube player
  • The First 12 Things You Should Do After Installing Debian 12 “Bookworm”!

    Debian 12 codenamed “Bookworm” is AWESOME! If you’re the proud owner of a brand new Debian install, then this is the video for you! We’ll go over 12 things you should consider implementing in Debian 12, from productivity apps to gaming. This is definitely a can’t-miss video for Debian fans!

    YouTube player

    Thanks to Akamai for sponsoring today’s video! Check out their awesome cloud platform to get set up with your very own Linux server!

    (more…)
  • Debian 12 “Bookworm” is the Best Release of Debian. Ever.

    Debian 12 (codenamed “Bookworm”) is a FANTASTIC release of an awesome Linux distribution, and this is a release that fans of the popular desktop distro are sure to love. In this video, Jay goes over all the reasons why he feels that this is the best Debian release ever. This review will include a look at the installation process, performance, stability, and a surprising change. And speaking of “surprising”, there’s a surprise twist at the end of the review that will be sure to shock long-time fans of the channel. Check it out!

    YouTube player
  • Debian 12 “Net Install” Installation Walkthrough

    Debian is a distribution loved by many, and one of the most popular of all time. If you’re thinking of installing it on your computer, then this installation guide will cover the “Net Install” method from beginning to end. In this video, you’ll see the process of wiping your drive and replacing your OS with Debian from start to finish!

    Note: The installation screen captures are a lower resolution than normal due to a screen recorder issue.

    YouTube player

    Thanks to Akamai for sponsoring today’s video! Check out their awesome cloud platform to get set up with your very own Linux server!

  • Build Your Own Mastodon Server on Debian (Step by Step Server Build Guide)

    There’s way too much drama with Twitter nowadays, so the alternatives are looking more attractive than ever. Setting up your own Mastodon server is a fun project, and also a potential alternative to Twitter. In this video, Jay walks you through the entire process of setting up your own Mastodon server on a Debian-based VPS.

    YouTube player
    (more…)
  • SCaLE 19x – Debian, Linux Chix LA, and Jenkins!

    LearnLinuxTV was present at the Southern California Linux Expo (SCaLE) this year (courtesy of Linode) and what a fantastic event it was! In the final video regarding the 19th annual SCaLE, you’ll see interviews with representatives from Debian, Linux Chix LA, and Jenkins. Look out for even more SCaLE action next year!

    YouTube player

    Relevant Links