Skip to content

Set Up Nextcloud on a Linux Server – Build Your Private Cloud

Set up Nextcloud on your Linux VPS and create your own private cloud for files, calendars, and more → Learn more now

27 November 202613 min read93 Views0 helpful

Introduction

Nextcloud is an open-source cloud solution and a fork of ownCloud, founded in 2016 by former ownCloud founder Frank Karlitschek. With Nextcloud, you can run your own private cloud for files, calendars, contacts, chat, and video calls—fully under your control instead of relying on another provider.

This guide shows you two ways to get started: the easy way, using a One-Click App that sets up Nextcloud with admin access, HTTPS, and background jobs automatically, and a manual installation using Apache, PHP, and a database via the console. Afterward, you can connect your devices and extend Nextcloud with apps.

When it makes sense to run Nextcloud on a VPS

Nextcloud also runs on a NAS or a computer at home. A VPS in a data center is a good fit if:

  • You want to host your files, calendars, and contacts yourself instead of storing them with Google, Microsoft, or Dropbox.
  • You want your cloud to always be available, regardless of a power outage, DSL issue, or a device at home that would otherwise need to run around the clock.
  • Several people will use it, such as family or a team, each with their own account and sharing options via links with a password and expiration date.
  • You want to keep all your devices in sync: desktop clients for Windows, macOS, and Linux, as well as apps for Android and iOS, automatically sync your files.
  • You might need more later: add Talk, Deck, Notes, or Office as apps in Nextcloud.

A VPS is less suitable if you want to store several terabytes of photos and videos, because VPS storage is limited. For a photo library alone, Immich is a better choice; for streaming movies and series, try Jellyfin.

Which database: SQLite or a database server?

Nextcloud stores accounts, shares, and file information in a database. The files themselves are stored separately in the data directory. You make this choice for either setup method:

SQLiteMariaDB or MySQLPostgreSQL
Entry in the One-Click Apps catalogNextcloud (no extra name)Nextcloud with MariaDB or MySQL in the nameNextcloud with Postgres in the name
Suitable forTrying it out, one person, a few filesAlways-on use, family, or teamAlways-on use, family, or team
Additional cache (Redis) in the One-Click AppNoYesYes
For manual installationNothing else neededInstall a database serverInstall a database server
Tip

For always-on use with a database Nextcloud itself recommends SQLite only for testing and very small installations. If you want to use Nextcloud regularly, choose MariaDB, MySQL, or PostgreSQL. Switching databases later is time-consuming.

Easy option: Nextcloud as a One-Click App

The quickest way to get your own Nextcloud is through your VPS's One-Click Apps. The app sets itself up on first launch: it creates an admin account and takes care of the domain, HTTPS, and background jobs. You don't need to go through a setup wizard or use the console.

Requirements

  • A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. See Set up One-Click Apps for instructions.
  • At least 512 MB RAM for Nextcloud; 1 GB is recommended. You'll need more for many users or apps such as Nextcloud Office.

Install

  1. Open your VPS in the ZapX dashboard and switch to the One-Click Apps tab.
  2. Search the app catalog for Nextcloud, select the right variant (see the table above), and click Install app.
  3. Under Use a custom subdomain or zap.cloud, choose an address for your cloud. With a domain, Nextcloud is available via HTTPS. Without a domain, the app only runs over HTTP, which you shouldn't use for a cloud containing your files.
  4. Enter your time zone under TZ, for example, Europe/Berlin. The default is Europe/Madrid, or Europe/Paris for the variants with a database.
  5. Click Queue installation. Nextcloud installs itself on first launch, which takes a few minutes.

First login

The app creates the admin account during installation. You'll find the credentials in the app settings (gear icon) under App environment > Automatically generated values: SERVICE_USER_ADMIN is the username (default zapx), and SERVICE_PASSWORD_ADMIN is the password. Click the eye icon to reveal it or the copy icon to copy it. Open the app's address and log in. You can then set your own password in Nextcloud under your profile picture > Personal settings > Security.

What the app sets up for you

  • Domain: The app's address is added as a trusted domain. If you change the domain in ZapX later, the new address is added automatically the next time the app starts.
  • HTTPS: When you use a domain, Nextcloud doesn't redirect to http://, and links in emails and shares point to the correct address.
  • Background jobs: Nextcloud runs cleanup and maintenance tasks every 5 minutes via Cron. If you've configured a different method yourself, your settings are preserved.
  • Upload limit: By default, uploads up to 512 MB are allowed. To increase this, create the PHP_UPLOAD_LIMIT variable under App environment, for example, with the value 2G. After you save, the app restarts and the new limit takes effect.

Updates and backups

Don't update Nextcloud from within Nextcloud itself; the updater there is disabled in the app. Instead, open the app settings (gear icon) > App update and click Check for updates. If a new version is available, install it by clicking Apply update.

Your files, settings, and database are stored in separate volumes on your VPS and are preserved during an update. However, back up your VPS beforehand using the backups in the web interface so you can restore it if needed.

For what to do next (users, devices, and apps), see “Using Nextcloud: Connect devices and apps” below. For common issues and their solutions, see Nextcloud: Common issues.

Manual installation

The rest of this guide describes a manual installation on a Linux server via the console. For example, you might choose this option if you want to integrate Nextcloud into an existing server environment or control every configuration step yourself.

Requirements

  • A Linux VPS running Ubuntu or Debian, with SSH access. If you're not sure how SSH works, see First access (SSH).
  • For HTTPS, a domain or subdomain whose A record points to your VPS's IP address (e.g. cloud.example.com).

The following requirements are based on Nextcloud's official system requirements and our own experience. Nextcloud updates its PHP and database requirements with new major versions, so check them before installing.

Hardware

ComponentsMinimumRecommended
CPU1x 2 GHz4x 2+ GHz
RAM1 GB4+ GB
Storage10 GB50+ GB (depending on the amount of data stored)
Bandwidth100 Mbit/s (up & down)500 Mbit/s (up & down) if several people use the cloud

Software

PlatformOptions
Operating systemUbuntu (22.04, 24.04), Debian (12, 13)
DatabaseMariaDB 10.11+ (recommended), PostgreSQL 14+, MySQL 8.0+, SQLite (for testing and minimal installations only)
Web serverApache 2.4 with mod_php or php-fpm (recommended), or Nginx with php-fpm
PHP8.3, 8.4, 8.5 (recommended)

Prepare the firewall

Allow only SSH and the ports for HTTP and HTTPS. With ufw, it looks like this:

Code
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable

This keeps the database inaccessible from outside; it only runs locally on the server. Learn more in Firewall management on Linux.

Warning

Complete the setup right away Until Nextcloud has been set up, anyone who knows the address can open the web installer and create the administrator account. For this reason, complete the installation in one go.

Install the web server and PHP

Install Apache and PHP along with the extensions Nextcloud requires (including gd, curl, mbstring, xml, zip, intl, bcmath, gmp, apcu).

🗄️ Ubuntu 24.04 and Debian 13 “trixie” (include PHP 8.3 or 8.4 by default):

Code
sudo apt update && sudo apt -y upgrade
sudo apt -y install apache2 php php-cli php-fpm php-common php-mysql php-pgsql php-sqlite3 php-zip php-gd php-mbstring php-curl php-xml php-bcmath php-intl php-gmp php-imagick php-apcu

🗄️ Ubuntu 22.04 (the default PHP version is 8.1, which is too old for current Nextcloud versions, so a PPA is required):

Code
sudo apt update && sudo apt -y upgrade
sudo apt -y install apache2 software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
sudo apt -y install php8.3 php8.3-cli php8.3-fpm php8.3-common php8.3-mysql php8.3-pgsql php8.3-sqlite3 php8.3-zip php8.3-gd php8.3-mbstring php8.3-curl php8.3-xml php8.3-bcmath php8.3-intl php8.3-gmp php8.3-imagick php8.3-apcu

🗄️ Debian 12 “bookworm” (the default PHP version is 8.2, which is too old for current Nextcloud versions, so a third-party repository is required):

Code
sudo apt update && sudo apt -y upgrade
sudo apt -y install apache2 lsb-release apt-transport-https ca-certificates wget
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update
sudo apt -y install php8.3 php8.3-cli php8.3-fpm php8.3-common php8.3-mysql php8.3-pgsql php8.3-sqlite3 php8.3-zip php8.3-gd php8.3-mbstring php8.3-curl php8.3-xml php8.3-bcmath php8.3-intl php8.3-gmp php8.3-imagick php8.3-apcu

Check the version with php -v.

Info

PHP memory limit Nextcloud requires memory_limit = 512M or higher. Set this value in the relevant php.ini file (e.g. /etc/php/8.3/apache2/php.ini; the version number in the path should match your PHP version), then restart Apache with sudo systemctl restart apache2.

Set up the database

Choose one of the options in the table above and follow only the steps for your selection.

MariaDB or MySQL

Install the database server, either mariadb-server (recommended) or mysql-server:

Code
sudo apt -y install mariadb-server

On Debian and Ubuntu, you can log in as root without a password using your system user. Create the database and a separate user for Nextcloud:

sql
sudo mysql
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'nc_user'@'localhost' IDENTIFIED BY 'DEIN_PASSWORT_HIER';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nc_user'@'localhost';
FLUSH PRIVILEGES;
exit

Never use the database root user for Nextcloud. Then run sudo mysql_secure_installation to remove anonymous users and the test database.

PostgreSQL

Code
sudo apt -y install postgresql
sudo -u postgres psql
sql
CREATE USER nc_user WITH ENCRYPTED PASSWORD 'DEIN_PASSWORT_HIER';
CREATE DATABASE nextcloud OWNER nc_user;
\q

Here, too, don't use the postgres superuser for Nextcloud.

SQLite

SQLite is only suitable for testing or very small single-user installations. You already installed the php-sqlite3 PHP module above, and Nextcloud creates the database file itself during setup.

Install Nextcloud and open it for the first time

Download the latest stable version directly from the Nextcloud servers and create a data directory outside the web root:

Code
cd /var/www/
sudo apt -y install unzip wget
sudo wget https://download.nextcloud.com/server/releases/latest.zip
sudo unzip latest.zip
sudo rm latest.zip
sudo chown -R www-data:www-data nextcloud
sudo mkdir /home/cloud
sudo chown -R www-data:www-data /home/cloud

Create a VirtualHost for your domain using sudo nano /etc/apache2/sites-available/nextcloud.conf:

Code
<VirtualHost *:80>
    DocumentRoot /var/www/nextcloud/
    ServerName cloud.example.com

    <Directory /var/www/nextcloud/>
        Require all granted
        AllowOverride All
        Options FollowSymLinks MultiViews

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

Enable the site and the Apache modules Nextcloud needs:

Code
sudo a2ensite nextcloud.conf
sudo a2dissite 000-default.conf
sudo a2enmod rewrite headers env dir mime
sudo systemctl reload apache2

Now open http://cloud.example.com in your browser. In the installer, create the administrator account, enter /home/cloud as the data directory under “Storage & database,” and enter the database credentials from above (database name, username, password, host localhost).

Info

Install without a browser Alternatively, you can install Nextcloud entirely from the command line using sudo -u www-data php occ maintenance:install .... This means the web installer is never exposed. For details, see the official occ documentation.

Access via HTTPS

A cloud containing your files should only be accessible over an encrypted connection; otherwise, data and passwords are transmitted over the network in plain text. Get a free certificate with certbot. For the basics, see Create an SSL certificate (Let's Encrypt):

Code
sudo apt -y install certbot python3-certbot-apache
sudo certbot --apache --redirect -d cloud.example.com

Certbot creates the file /etc/apache2/sites-available/nextcloud-le-ssl.conf and permanently redirects HTTP to HTTPS. In this file, add the HSTS header that Nextcloud checks on the overview page inside <VirtualHost *:443>:

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

Reload Apache with sudo systemctl reload apache2. To make sure links from background jobs and emails also use HTTPS, set the address in Nextcloud as well:

Code
sudo -u www-data php /var/www/nextcloud/occ config:system:set overwrite.cli.url --value=https://cloud.example.com

Set up background jobs and cache

Nextcloud needs regular background jobs. Cron is the most reliable way to run them. Open the web server user's crontab with sudo crontab -u www-data -e and add this line:

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

Then switch Nextcloud to Cron and enable APCu as a cache:

Code
cd /var/www/nextcloud
sudo -u www-data php occ background:cron
sudo -u www-data php occ config:system:set memcache.local --value='\OC\Memcache\APCu'

To make Cron work with APCu, add the line apc.enable_cli=1 to /etc/php/8.3/mods-available/apcu.ini (use the version number for your PHP version) and restart Apache.

As an admin, check Administration settings > Overview for any remaining warnings and resolve them before using the cloud in production. Nextcloud: Common issues explains the most frequent warnings.

Back up your data

A complete backup consists of three parts: the /var/www/nextcloud folder (especially config), the data directory /home/cloud, and the database. Briefly enable maintenance mode for Nextcloud so that nothing changes during the backup. With MariaDB or MySQL, it looks like this:

Code
cd /var/www/nextcloud
sudo -u www-data php occ maintenance:mode --on
sudo tar -czf /root/nextcloud-files-$(date +%F).tar.gz /var/www/nextcloud /home/cloud
sudo mysqldump --single-transaction nextcloud > /root/nextcloud-db-$(date +%F).sql
sudo -u www-data php occ maintenance:mode --off

With PostgreSQL, replace the mysqldump line with sudo -u postgres pg_dump nextcloud > /root/nextcloud-db-$(date +%F).sql. With SQLite, the database is a file in the data directory and is already included in the archive. Download your backups regularly so they aren't stored only on the server.

Update Nextcloud

Back up your data as described above before every update. Start the updater from the console:

Code
sudo -u www-data php /var/www/nextcloud/updater/updater.phar

It downloads the new version and replaces the files. At the end, it asks whether to run occ upgrade (confirm with Y) and whether to leave maintenance mode enabled (answer N). Alternatively, start the updater in your browser under Administration settings > Overview.

Warning

Don't skip a major version Nextcloud can only be updated from one major version to the next—for example, from 31 to 32, not directly to 33. Before a major update, check whether your PHP version is still supported.

Also keep Apache, PHP, and the database up to date with sudo apt update && sudo apt upgrade. If Nextcloud remains in maintenance mode after an update, see Nextcloud: Common issues.

Using Nextcloud: Connect devices and apps

Whether you use a One-Click App or a manual installation, using Nextcloud is the same from this point on.

Create users

Create separate accounts for other people: profile picture > Accounts > New account. You can also set groups and a storage quota for each account here, so one person can't use all the storage on your VPS.

Connect your desktop and smartphone

You can get clients for Windows, macOS, and Linux, as well as apps for Android and iOS, from the Nextcloud download page. Enter your cloud's address as the server address, for example, https://cloud.example.com. You'll then sign in through your browser.

  • Desktop client: Syncs the selected folders with your computer. With virtual files, content is only downloaded when you open it.
  • Smartphone app: Shows your files and can automatically upload photos to the cloud if you want.
  • Calendar and contacts: Nextcloud supports CalDAV and CardDAV. On Android, you can use DAVx⁵, for example; on iPhone and Mac, add a CalDAV or CardDAV account in settings using your cloud's address.
  • As a network drive (WebDAV): The address is https://cloud.example.com/remote.php/dav/files/USERNAME/. You can also find it in the Files app under File settings.

Apps and security

Use the Apps menu to extend Nextcloud, for example with Calendar, Contacts, Talk (chat and video calls), Deck (Kanban boards), or Notes. Also enable two-factor authentication for your admin account: install the “Two-Factor TOTP Provider” app under Apps, then set it up with an authenticator app under Personal settings > Security. For more tips on securing your server, see Linux security tips.

Things to keep in mind

  • Storage space: All files are stored on your VPS. Make sure you leave space for versions and the trash; Nextcloud keeps older versions of deleted and modified files for a while.
  • Nextcloud Office: Editing documents in a browser requires an additional office server such as Collabora Online. It needs its own RAM, so plan for significantly more memory than Nextcloud alone requires.
  • Video calls with Talk: Calls with a few people work directly. For larger groups, Nextcloud recommends the High Performance Backend; some networks also require a TURN server.

Conclusion

You've set up Nextcloud on your VPS, secured it with HTTPS, and learned how to connect devices, back up data, and install updates. If you run into problems, see Nextcloud: Common issues.

Prefer not to use the console? Choose the easy option and use the One-Click App described above under “Easy option: Nextcloud as a One-Click App.” The app sets up admin access, HTTPS, and background jobs for you.

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

Nextcloud is an open-source cloud solution and a fork of ownCloud that lets you run your own private cloud for files, calendars, contacts, chat, and video calls—all under your control. The Nextcloud server itself is free.
The One-Click App is the quickest option: Nextcloud sets itself up, creates the admin account, prepares the domain, HTTPS, and background jobs, and lets you install updates through the web interface. A manual installation with Apache, PHP, and a database is a good choice if you want to integrate Nextcloud into an existing server environment or control every configuration step yourself.
For always-on use, choose MariaDB, MySQL, or PostgreSQL. Nextcloud recommends SQLite only for testing and very small, single-user installations. For One-Click Apps, select the variant with MariaDB, MySQL, or Postgres in its name; it also includes Redis as a cache.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.