How to Install Nextcloud on a VPS: Your Own Private Cloud Storage and Collaboration Suite

How to Install Nextcloud on a VPS: Your Own Private Cloud Storage and Collaboration Suite

Nextcloud is the leading self-hosted cloud platform — it replaces Dropbox for file storage, Google Calendar and Contacts for PIM, Zoom for video calls, and Google Docs for collaborative editing, all on your own VPS. Your files stay on your hardware, under your encryption keys, subject only to your privacy policy. This guide installs Nextcloud 29+ on Ubuntu with PHP-FPM, MariaDB, Nginx, Redis object caching, and Let’s Encrypt SSL.

What Nextcloud Includes

  • Files: Sync across desktop (Windows/Mac/Linux) and mobile (iOS/Android), sharing with links and passwords, versioning, and encryption
  • Calendar & Contacts: CalDAV/CardDAV server synced to any standard client (Apple Calendar, Thunderbird, Android)
  • Talk: Video calls and team chat
  • Office: Collaborative document editing via Collabora Online or OnlyOffice

Server Requirements

  • Ubuntu 22.04 or 24.04 LTS, minimum 2 GB RAM (4 GB recommended)
  • PHP 8.2, MariaDB 10.6+, Redis, Nginx
  • 40–500 GB NVMe depending on file storage needs

Step 1: Install Dependencies

sudo apt update && sudo apt upgrade -y

sudo apt install -y php8.2-fpm php8.2-cli php8.2-mysql php8.2-xml \
  php8.2-curl php8.2-gd php8.2-mbstring php8.2-zip php8.2-intl \
  php8.2-bcmath php8.2-gmp php8.2-redis php8.2-apcu php8.2-imagick

sudo apt install -y mariadb-server redis-server nginx certbot python3-certbot-nginx

Step 2: Configure PHP

sudo nano /etc/php/8.2/fpm/php.ini
memory_limit = 512M
upload_max_filesize = 10G
post_max_size = 10G
max_execution_time = 360
date.timezone = UTC
sudo systemctl restart php8.2-fpm

Step 3: Create Database

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

Step 4: Download Nextcloud

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

Step 5: Configure Nginx

sudo nano /etc/nginx/sites-available/nextcloud
upstream php-handler {
    server unix:/var/run/php/php8.2-fpm.sock;
}

server {
    listen 80;
    server_name cloud.yourdomain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name cloud.yourdomain.com;
    root /var/www/nextcloud;
    index index.php index.html;
    client_max_body_size 10G;

    add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-Frame-Options "SAMEORIGIN" always;

    location = /.well-known/carddav { return 301 $scheme://$host/remote.php/dav; }
    location = /.well-known/caldav  { return 301 $scheme://$host/remote.php/dav; }

    location / { rewrite ^ /index.php; }

    location ~ ^/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
        fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
        set $path_info $fastcgi_path_info;
        try_files $fastcgi_script_name =404;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param HTTPS on;
        fastcgi_pass php-handler;
        fastcgi_request_buffering off;
        fastcgi_read_timeout 300;
    }

    location ~ \.php$ { return 404; }

    location ~* \.(?:css|js|woff2|svg|gif|png|html|ttf|ico|jpg|jpeg|webp)$ {
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463";
        access_log off;
    }
}
sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d cloud.yourdomain.com

Step 6: Run Nextcloud Installation

cd /var/www/nextcloud
sudo -u www-data php occ maintenance:install \
  --database 'mysql' \
  --database-host 'localhost' \
  --database-name 'nextcloud' \
  --database-user 'nextcloud' \
  --database-pass 'StrongNextcloudPassword!' \
  --admin-user 'admin' \
  --admin-pass 'YourSecureAdminPassword!' \
  --data-dir '/var/nextcloud-data'

sudo -u www-data php occ config:system:set trusted_domains 1 --value='cloud.yourdomain.com'

Step 7: Configure Redis Caching

Add to /var/www/nextcloud/config/config.php before the closing );:

  'memcache.local' => '\OC\Memcache\APCu',
  'memcache.distributed' => '\OC\Memcache\Redis',
  'memcache.locking' => '\OC\Memcache\Redis',
  'redis' => [
    'host' => '127.0.0.1',
    'port' => 6379,
    'timeout' => 0.0,
  ],
sudo systemctl restart php8.2-fpm

Step 8: Configure Background Jobs

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

sudo -u www-data php /var/www/nextcloud/occ background:cron

Step 9: Performance Optimization

sudo nano /etc/php/8.2/fpm/conf.d/10-opcache.ini
opcache.enable=1
opcache.interned_strings_buffer=32
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=60
sudo systemctl restart php8.2-fpm
sudo -u www-data php occ db:add-missing-indices

Mobile Sync Setup

Install the Nextcloud app on iOS or Android, connect to https://cloud.yourdomain.com. CalDAV/CardDAV sync URLs:

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

Getting Started

Nextcloud requires at least 2 GB RAM; 4 GB recommended for teams with collaborative document editing. Ubuntu VPS plans at VPS.DO with NVMe storage provide fast file I/O for large uploads and thumbnail generation. The 40 GB NVMe plan suits personal use; 80–200 GB plans accommodate team file storage.

Conclusion

Nextcloud on a VPS delivers a private, self-hosted alternative to Dropbox, Google Workspace, and Zoom — with files stored on your hardware, calendar and contacts synced via standard protocols, and video calling without third-party servers. Redis object caching and OPcache bring Nextcloud’s performance close to commercial SaaS alternatives while data remains entirely under your control.

Fast • Reliable • Affordable VPS - DO It Now!

Get top VPS hosting with VPS.DO’s fast, low-cost plans. Try risk-free with our 7-day no-questions-asked refund and start today!