Nextcloud is a self-hosted alternative to Google Drive and Dropbox: file sync, sharing, calendars, contacts and an app store with office suites, notes and more. Running it on your own VPS means your files stay on a server you control.

There are two main ways to install it:

  • Nextcloud All-in-One (AIO) — a Docker-based installer that manages everything, including updates and backups. Easiest; good if the server is dedicated to Nextcloud.
  • Manual install on a LEMP stack — more control and fits next to other sites on the same server. That’s what this guide covers.

Requirements

  • Ubuntu 24.04 (or 22.04), a sudo user.
  • A domain pointing to the server, e.g. cloud.example.com.
  • At least 2 GB RAM for a few users; 4 GB+ for larger teams or Collabora/OnlyOffice.
  • Disk space for your files — the main sizing question. A Storage VPS gives you hundreds of gigabytes for this.

1. Install the stack

sudo apt update
sudo apt install -y nginx mariadb-server redis-server unzip \
  php-fpm php-mysql php-gd php-curl php-mbstring php-intl php-gmp \
  php-bcmath php-xml php-zip php-imagick php-redis php-apcu

Check your PHP version with php -v and confirm it’s supported by the Nextcloud release you’ll install (the admin manual lists supported versions).

2. Create the database

sudo mysql
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'a-long-random-password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
EXIT;

3. Download Nextcloud

cd /tmp
wget https://download.nextcloud.com/server/releases/latest.zip
wget https://download.nextcloud.com/server/releases/latest.zip.sha256
sha256sum -c latest.zip.sha256 < latest.zip
sudo unzip -q latest.zip -d /var/www/
sudo mkdir -p /srv/nextcloud-data
sudo chown -R www-data:www-data /var/www/nextcloud /srv/nextcloud-data

Keeping the data directory outside the web root (/srv/nextcloud-data) means a web-server misconfiguration can’t expose files directly.

4. Tune PHP

In /etc/php/8.3/fpm/php.ini (adjust the version):

memory_limit = 512M
upload_max_filesize = 10G
post_max_size = 10G
max_execution_time = 3600
output_buffering = 0
opcache.interned_strings_buffer = 16
opcache.memory_consumption = 256

In /etc/php/8.3/fpm/pool.d/www.conf, uncomment env[PATH] = /usr/local/bin:/usr/bin:/bin. Then sudo systemctl restart php8.3-fpm.

5. Configure Nginx

Nextcloud needs a fairly specific Nginx configuration (rewrites, .well-known redirects, security headers, blocked paths). The Nextcloud admin manual publishes a complete, maintained example — copy it into /etc/nginx/sites-available/nextcloud, then set:

  • server_name cloud.example.com;
  • root /var/www/nextcloud;
  • the upstream php-handler to your PHP-FPM socket, e.g. server unix:/run/php/php8.3-fpm.sock;
  • client_max_body_size 10G;

Using the official template avoids most warnings on Nextcloud’s admin overview page.

sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

6. HTTPS

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

See Let’s Encrypt with Certbot on Nginx.

7. Run the installer

From the command line (or open https://cloud.example.com and use the web form):

cd /var/www/nextcloud
sudo -u www-data php occ maintenance:install \
  --database mysql --database-name nextcloud \
  --database-user nextcloud --database-pass 'a-long-random-password' \
  --admin-user admin --admin-pass 'admin-password' \
  --data-dir /srv/nextcloud-data
sudo -u www-data php occ config:system:set trusted_domains 1 --value=cloud.example.com

8. Caching with APCu and Redis

Add to /var/www/nextcloud/config/config.php:

'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => [
  'host' => '/var/run/redis/redis-server.sock',
  'port' => 0,
],

For the socket, enable unixsocket /var/run/redis/redis-server.sock and unixsocketperm 770 in /etc/redis/redis.conf, add www-data to the redis group, and restart Redis and PHP-FPM. Enable APCu for the CLI too: apc.enable_cli=1 in /etc/php/8.3/mods-available/apcu.ini.

9. Background jobs via cron

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

Then select Cron under Administration settings → Basic settings.

10. Check the admin overview

Administration settings → Overview runs security and setup checks and explains each warning. Work through them — typical items are missing phone region (default_phone_region), maintenance window start time, and email server settings.

Updates

cd /var/www/nextcloud
sudo -u www-data php updater/updater.phar
sudo -u www-data php occ upgrade

Nextcloud supports upgrading one major version at a time. Back up first.

Backups

Back up three things: the data directory, config/config.php, and the database:

sudo -u www-data php occ maintenance:mode --on
sudo mysqldump --single-transaction nextcloud > /var/backups/nextcloud-db.sql
sudo rsync -a /srv/nextcloud-data/ /backup/nextcloud-data/
sudo -u www-data php occ maintenance:mode --off

See mysqldump backup and restore and BorgBackup for automated, offsite copies.

Alternatives

If you mainly need fast file sync rather than a groupware suite, look at Seafile or the lighter SFTPGo. For photo backup specifically, Immich is excellent.

Nextcloud needs disk space more than CPU. Our Storage VPS plans pair large disks with enough RAM to run it smoothly.

  • Nextcloud
  • Self-Hosting
  • Ubuntu