How to Install Nextcloud on a VPS

Written by the ApexVPS team • Last updated: July 2026 • 9 min read

This nextcloud vps setup guide walks you through hosting your own private cloud — files, calendars, contacts and photos — on a server you fully control. Running Nextcloud on a VPS gives you dedicated resources, full root access and no per-user subscription, so your data stays yours. Below you will find the prerequisites, two proven installation paths (Docker Compose or a manual LAMP stack), how to add HTTPS with Let's Encrypt, plus the tuning and backup steps that keep the server fast and safe. Every command targets a fresh Ubuntu or Debian server.

Why self-host Nextcloud on a VPS?

Nextcloud is an open-source platform that replaces Google Drive, Dropbox and much of a productivity suite with software you run yourself. A VPS is the natural home for it: unlike shared hosting, you get root access, a fixed monthly cost and predictable performance. On a truly dedicated VPS there are no noisy neighbours competing for CPU, which matters once several people are syncing files at once. If you are weighing which services are worth running yourself, our overview of choosing a VPS for self-hosting compares the common workloads and how much headroom each one needs.

Prerequisites before you start

You need three things: a VPS with Ubuntu 22.04/24.04 or Debian 12, a domain name you can edit DNS for, and SSH access to the server as a user with sudo. A domain is not strictly required for testing, but you cannot issue a trusted TLS certificate without one, so treat it as mandatory for real use.

Choosing the right VPS size

Sizing depends on how many people use the server and whether you store media. For a single user or a family syncing documents, 2 vCPU and 4 GB RAM is comfortable. Once you add the Photos, Memories or media apps, or bring on more than a handful of active accounts, step up to a Business-class plan or higher — the extra RAM, faster NVMe and hourly snapshots make thumbnail generation and previews far smoother. You can compare the tiers on our VPS pricing page; scaling up later is quick, so it is fine to start modest and grow.

Point your domain at the server

Create an A record (and an AAAA record if you use IPv6) that points a hostname such as cloud.example.com at your server's public IP. DNS can take a little time to propagate. Confirm it resolves before requesting a certificate:

dig +short cloud.example.com

Path 1 — Nextcloud with Docker Compose

Containers are the fastest way to get a clean, repeatable install, and they keep Nextcloud, its database and cache isolated from the rest of the system. If containers are new to you, our beginner's guide to Docker on a VPS covers the fundamentals first. Install Docker using the official convenience script, then add your user to the docker group:

curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
# log out and back in so the group change takes effect

Create a project folder and a compose.yaml that runs Nextcloud with MariaDB and Redis. The app is bound to 127.0.0.1:8080 so it is only reachable through the reverse proxy you add later, not directly from the internet:

mkdir ~/nextcloud && cd ~/nextcloud
nano compose.yaml
services:
  db:
    image: mariadb:10.11
    restart: always
    command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
    volumes:
      - db:/var/lib/mysql
    environment:
      - MARIADB_ROOT_PASSWORD=change-this-root-password
      - MYSQL_PASSWORD=change-this-db-password
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  redis:
    image: redis:alpine
    restart: always

  app:
    image: nextcloud:apache
    restart: always
    ports:
      - "127.0.0.1:8080:80"
    depends_on:
      - db
      - redis
    volumes:
      - nextcloud:/var/www/html
    environment:
      - MYSQL_HOST=db
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=change-this-db-password
      - REDIS_HOST=redis

volumes:
  db:
  nextcloud:

Start the stack and check that all three containers come up:

docker compose up -d
docker compose ps

Nextcloud is now listening on localhost:8080. Skip ahead to the TLS section to expose it securely over HTTPS.

Path 2 — Manual install on a LAMP stack

If you prefer to manage the components yourself, a classic Linux, Apache, MariaDB and PHP (LAMP) install gives you full control. Update the system and install the web server, database and the PHP extensions Nextcloud expects:

sudo apt update && sudo apt upgrade -y
sudo apt install -y apache2 mariadb-server libapache2-mod-php unzip \
  php php-gd php-mysql php-curl php-mbstring php-intl php-xml \
  php-zip php-bcmath php-gmp php-imagick

Lock down the database, then create a dedicated database and user:

sudo mysql_secure_installation
sudo mysql -u root -p
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'change-this-db-password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Download the latest release into the web root and set ownership so Apache can write to it:

cd /var/www
sudo wget https://download.nextcloud.com/server/releases/latest.zip
sudo unzip latest.zip
sudo chown -R www-data:www-data /var/www/nextcloud

Create an Apache virtual host for your domain, enable it along with the modules Nextcloud needs, and reload:

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

Secure it with TLS (Let's Encrypt)

Never run Nextcloud over plain HTTP — logins and files would travel unencrypted. Certbot from the Let's Encrypt project issues a free, trusted certificate and renews it automatically. For the manual Apache install, use the Apache plug-in:

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

For the Docker path, put Nginx in front as a reverse proxy that forwards to 127.0.0.1:8080, then let Certbot secure it:

sudo apt install -y nginx certbot python3-certbot-nginx
sudo certbot --nginx -d cloud.example.com

Certbot installs a systemd timer that renews certificates before they expire. You can confirm renewal works with a dry run:

sudo certbot renew --dry-run

First-run setup

Open https://cloud.example.com in a browser. On the setup screen, create your administrator account and, for the manual install, enter the database name, user and password you created earlier (the Docker image is already wired to its database, so it skips this step). Finish the wizard and Nextcloud lands on the Files view. Immediately add your domain to the list of trusted_domains if you see a warning — for Docker that means editing the config inside the container:

docker compose exec -u www-data app \
  php occ config:system:set trusted_domains 1 --value=cloud.example.com

On the manual install the same command runs from the install directory with sudo -u www-data php /var/www/nextcloud/occ .... The occ command-line tool is your main administration entry point from here on.

Tuning and background jobs

A default install works, but a few changes make a real difference. Switch background jobs from AJAX to system cron so tasks run reliably even when nobody is logged in. On the manual install, add a cron entry for the web user:

sudo crontab -u www-data -e
# add this line, then save:
*/5 * * * * php -f /var/www/nextcloud/cron.php

Then set the "Cron" option under Administration → Basic settings. Other worthwhile tweaks: raise PHP memory_limit to at least 512M, enable Redis for file locking and caching (already included in the Compose file above), and set a maintenance window so heavy jobs run overnight. Running the built-in checks helps you catch anything missing:

sudo -u www-data php /var/www/nextcloud/occ status
sudo -u www-data php /var/www/nextcloud/occ setupchecks

Backups you can actually restore

Your VPS snapshots are the first line of defence — daily backups on Starter Pro, hourly snapshots on Business and Enterprise — but a good habit is a separate application-level backup you can restore file by file. Put Nextcloud into maintenance mode, dump the database, archive the data directory, then switch maintenance mode off:

sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on
mysqldump --single-transaction -u nextcloud -p nextcloud > nextcloud-db.sql
sudo tar -czf nextcloud-data.tar.gz /var/www/nextcloud/data
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off

For the Docker install, run the same occ calls through docker compose exec -u www-data app php occ ... and back up the named volumes. Store at least one copy off the server, and test a restore occasionally — an untested backup is only a hope.

Keeping it running

Update Nextcloud through the built-in updater or the web interface shortly after each release, keep the operating system patched with sudo apt upgrade, and review the Security & setup warnings panel in the admin area. With DDoS protection, private networking and 24/7 monitoring on the infrastructure side, and Let's Encrypt plus regular updates on the application side, a self-hosted Nextcloud is a genuinely dependable alternative to the big cloud suites.

Frequently asked questions

How much RAM does a Nextcloud VPS setup need?

For one user or a family syncing documents, 4 GB RAM and 2 vCPU is comfortable. Add photo or video libraries, preview generation or several active users and a Business-class plan with 8 GB RAM and faster NVMe is a better fit. Enterprise adds 16 GB and NVMe RAID for larger teams.

Should I choose the Docker or the manual LAMP install?

Pick Docker Compose if you want a clean, repeatable stack that is easy to move or rebuild, and the manual LAMP path if you prefer to manage Apache, PHP and MariaDB directly. Both are fully supported on a VPS with root access; the end result is the same Nextcloud.

Is a self-hosted Nextcloud secure?

Yes, when configured properly: serve everything over HTTPS with a Let's Encrypt certificate, keep the OS and Nextcloud updated, use strong passwords with two-factor authentication, and rely on your VPS backups. Because you host it yourself, no third party has standing access to your files.

Do I need a domain name?

Effectively yes. You can test against a raw IP address, but a trusted TLS certificate requires a domain, and mobile and desktop sync clients expect a proper HTTPS hostname. A single low-cost domain with an A record pointing at your server is all it takes.

Can I pay without a credit card?

Yes. ApexVPS checkout is crypto-only through OxaPay, accepting Bitcoin, Ethereum, USDT and 30+ coins — no credit card or bank account. Signup only needs an email to send your access details, plus optional notes such as an SSH key or preferred OS. No name, address or KYC is required.

Ready to host your own cloud? See VPS plans built for self-hosting →