Install Nextcloud on VPS: Private File Server

Install Nextcloud on VPS: Private File Server

June 2026 · 8 min read

Nextcloud is an open-source file hosting platform that works like Google Drive but runs entirely on your own server. All files stay on your VPS — no third-party company can scan, access, or sell your data. Nextcloud ships with native apps for iOS, Android, Windows, Mac, and Linux, plus built-in Calendar, Contacts, and Talk (video conferencing) so you have a complete productivity suite in one place.

Install Nextcloud with Docker

mkdir -p ~/nextcloud
cd ~/nextcloud

cat > docker-compose.yml << 'EOF'
version: "3.8"
services:
  db:
    image: mariadb:10.11
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: rootpass123
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
      MYSQL_PASSWORD: ncpass123
    volumes:
      - db_data:/var/lib/mysql

  nextcloud:
    image: nextcloud:latest
    restart: unless-stopped
    ports:
      - "8080:80"
    environment:
      MYSQL_HOST: db
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
      MYSQL_PASSWORD: ncpass123
      NEXTCLOUD_TRUSTED_DOMAINS: cloud.yourdomain.com
    volumes:
      - nc_data:/var/www/html
    depends_on:
      - db

volumes:
  db_data:
  nc_data:
EOF

docker compose up -d

Configure Nginx Reverse Proxy + SSL

sudo nano /etc/nginx/sites-available/nextcloud

server {
    listen 443 ssl;
    server_name cloud.yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/cloud.yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/cloud.yourdomain.com/privkey.pem;

    add_header Strict-Transport-Security "max-age=31536000" always;

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        client_max_body_size 10G;
        proxy_read_timeout 300s;
    }
}

Set Up Nextcloud via Web Installer

# Open https://cloud.yourdomain.com for the first time
# Fill in:
# Admin username: admin
# Admin password: (create your own)
# Data folder: /var/www/html/data
# Database: MySQL
# Database host: db
# Database name/user/pass from your compose file

# Or install via command line
docker exec -u www-data nextcloud-nextcloud-1 php occ maintenance:install \
  --database mysql --database-name nextcloud \
  --database-user nextcloud --database-pass ncpass123 \
  --admin-user admin --admin-pass adminpass123

Optimize Performance (PHP OPcache + Redis)

# Add Redis to docker-compose.yml
  redis:
    image: redis:alpine
    restart: unless-stopped

# Configure Nextcloud to use Redis
docker exec -u www-data nextcloud-nextcloud-1 php occ config:system:set \
  memcache.local --value '\OC\Memcache\APCu'
docker exec -u www-data nextcloud-nextcloud-1 php occ config:system:set \
  memcache.distributed --value '\OC\Memcache\Redis'
docker exec -u www-data nextcloud-nextcloud-1 php occ config:system:set \
  redis --type json --value '{"host":"redis","port":6379}'
Tip: Install the Nextcloud client on Mac/Windows and sync a folder of your choice. Files will upload/download automatically like Dropbox, but your data stays completely under your control on your own VPS.

Verify Nextcloud is Working Correctly

# Check container status
docker compose ps

# Check Nextcloud health
docker exec -u www-data nextcloud-nextcloud-1 php occ status

# Show warnings and errors
docker exec -u www-data nextcloud-nextcloud-1 php occ check

# View application logs
docker compose logs nextcloud | tail -50
Tip: Log into the Nextcloud admin panel and go to Settings > Administration > Overview. You'll see a security checklist and performance warnings with recommended fixes you can apply immediately.

Common Issues & Troubleshooting

Error: "Access through untrusted domain"

You need to add your domain to the trusted_domains list in config.php:

docker exec -u www-data nextcloud-nextcloud-1 php occ config:system:set \
  trusted_domains 1 --value="cloud.yourdomain.com"

Large file uploads fail (max upload size)

You must configure both Nginx and PHP inside the container:

docker exec nextcloud-nextcloud-1 bash -c \
  "echo 'upload_max_filesize=10G' >> /usr/local/etc/php/conf.d/nextcloud.ini && \
   echo 'post_max_size=10G' >> /usr/local/etc/php/conf.d/nextcloud.ini"
docker compose restart nextcloud

Calendar/Contacts won't sync with iPhone

You need to set the correct CalDAV/CardDAV URL in iPhone Settings:

# CalDAV URL
https://cloud.yourdomain.com/remote.php/dav/principals/users/USERNAME/

# Or use auto-discovery
https://cloud.yourdomain.com/.well-known/caldav

Nextcloud is slow during file scanning

Disable overlapping background jobs and use cron instead of AJAX:

docker exec -u www-data nextcloud-nextcloud-1 php occ background:cron
crontab -e
# Add:
*/5 * * * * docker exec -u www-data nextcloud-nextcloud-1 php -f /var/www/html/cron.php

Frequently Asked Questions

What is the difference between Nextcloud and Seafile?

Nextcloud has a more complete ecosystem (Calendar, Talk, Office suite, 200+ apps) but is heavier than Seafile. Seafile is faster if you only need file synchronization. Choose Seafile if your team only needs high-performance file storage; choose Nextcloud if you want a full productivity platform with contacts, calendar, and video conferencing built in.

Does Nextcloud support two-factor authentication (2FA)?

Yes. Nextcloud supports TOTP (Google Authenticator), WebAuthn/FIDO2, and Email OTP through the Two-Factor Auth app available in the App Store within the admin panel. You can enforce 2FA globally for all users or selectively for admin accounts only.

How do I back up Nextcloud?

You need to back up two components: the file data directory and the MySQL database. Use rsync + mysqldump on a schedule, or install the Nextcloud Backup app which automates both parts. For production setups, back up at least daily and test restore procedures monthly.