Tutorials / Nextcloud

How to Deploy Nextcloud on a VPS

intermediate75 minLast reviewed: 2026-04-30

Nextcloud is more demanding than a simple PHP site because it stores user files, previews, calendars, contacts, app data, and background jobs. It benefits from Redis, tuned PHP limits, HTTPS, and a real backup plan. A VPS gives you control over those pieces, but it also makes you responsible for updates and storage planning.

This guide uses Apache, PHP, MariaDB, Redis, and Let's Encrypt on Ubuntu 24.04. It is appropriate for a personal or small-team Nextcloud. For heavy file sync, many users, or large media collections, plan extra disk and monitor I/O carefully.

Illustration for How to Deploy Nextcloud on a VPS

Prerequisites

  • A uNode VPS deployed with Ubuntu 24.04 LTS.
  • A domain name pointing at the VPS public IP.
  • Enough disk for user files; Standard is a starting point, but storage growth matters.
  • Root SSH access.
Open console server deploy

Step 1

Install packages

Install Apache, MariaDB, Redis, PHP, and the PHP extensions Nextcloud expects. Keep the base system current before adding the application.

ssh root@<your-server-ip>
apt update && apt upgrade -y
apt install -y apache2 mariadb-server redis-server unzip bzip2 curl libapache2-mod-php php php-gd php-mysql php-curl php-mbstring php-intl php-gmp php-bcmath php-xml php-imagick php-zip php-redis

Step 2

Create a database

Use a dedicated database and user. Store the password somewhere safe. Nextcloud writes frequently, so the database is part of your backup plan, not disposable metadata.

mariadb
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'replace-with-a-long-password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 3

Download Nextcloud

Download the current release from nextcloud.com and place it under /var/www. The data directory can live outside the web root; for small installs, /var/ncdata is clear and easy to back up.

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

Step 4

Tune PHP for Nextcloud

Nextcloud needs larger upload limits than a default PHP install. Adjust both Apache PHP and CLI PHP so web requests and background jobs behave consistently.

PHP_INI=/etc/php/8.3/apache2/php.ini
sed -i 's/^memory_limit = .*/memory_limit = 512M/' $PHP_INI
sed -i 's/^upload_max_filesize = .*/upload_max_filesize = 1024M/' $PHP_INI
sed -i 's/^post_max_size = .*/post_max_size = 1024M/' $PHP_INI
sed -i 's/^max_execution_time = .*/max_execution_time = 360/' $PHP_INI
cp $PHP_INI /etc/php/8.3/cli/php.ini

Step 5

Configure Apache and TLS

Enable the Apache modules Nextcloud uses and create a virtual host. Then request a Let's Encrypt certificate after DNS points at the VPS.

a2enmod rewrite headers env dir mime ssl
cat >/etc/apache2/sites-available/nextcloud.conf <<'EOF'
<VirtualHost *:80>
    ServerName cloud.example.com
    DocumentRoot /var/www/nextcloud

    <Directory /var/www/nextcloud/>
        Require all granted
        AllowOverride All
        Options FollowSymLinks MultiViews
    </Directory>
</VirtualHost>
EOF
a2ensite nextcloud.conf
a2dissite 000-default.conf
systemctl reload apache2
apt install -y certbot python3-certbot-apache
certbot --apache -d cloud.example.com

Step 6

Run the web installer and enable Redis

Open https://cloud.example.com and complete the installer using the database credentials. After setup, configure Redis file locking and caching. This improves reliability under sync load and avoids unnecessary database locking pressure.

sudo -u www-data php /var/www/nextcloud/occ config:system:set memcache.local --value='\\OC\\Memcache\\APCu'
sudo -u www-data php /var/www/nextcloud/occ config:system:set memcache.locking --value='\\OC\\Memcache\\Redis'
sudo -u www-data php /var/www/nextcloud/occ config:system:set redis host --value='localhost'
sudo -u www-data php /var/www/nextcloud/occ config:system:set redis port --value=6379 --type=integer

Step 7

Background jobs, app passwords, and clients

Use cron for background jobs instead of AJAX. For phones and desktop sync clients, create app passwords rather than reusing the main account password. This makes revocation easier if a device is lost.

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

Step 8

Back up data and database

Back up the database, config directory, and data directory. Nextcloud stores important state in both database and filesystem. Test restores on a separate server before depending on the backup process. If storage grows quickly, move large backups off the VPS so a full disk does not take down sync.

mariadb-dump nextcloud > /root/nextcloud-db-$(date +%F).sql
tar -czf /root/nextcloud-config-$(date +%F).tar.gz /var/www/nextcloud/config
tar -czf /root/nextcloud-data-$(date +%F).tar.gz /var/ncdata