On this page
- What do you need before installing Nextcloud?
- How do you install Nginx, PHP, MariaDB and Redis?
- How do you prepare the database and PHP?
- How do you download and install Nextcloud?
- What does the Nginx server block look like?
- How do you add HTTPS and open the firewall?
- How do you set up cron, caching and mail?
- How do you check the install and keep it updated?
- What should you check when something breaks?
- Questions
What do you need before installing Nextcloud?
You need a fresh Ubuntu 24.04 or Debian 12/13 server, a sudo user, a DNS name such as cloud.example.net pointing at the server, and enough disk for the files you plan to store. Nextcloud keeps uploads on the local disk of the plan, so choose the plan by storage first and memory second.
- Memory: 2 GB runs a personal instance; 4 GB keeps previews, calendar sync and several desktop clients responsive.
- PHP: Ubuntu 24.04 ships PHP 8.3, Debian 12 ships 8.2 and Debian 13 ships 8.4. Check the PHP range your Nextcloud release supports in its admin manual before you pick Ubuntu 22.04, whose PHP 8.1 is too old for current releases.
- DNS: create the A and AAAA records first, as described in DNS records, so the certificate request succeeds later.
Log in as your normal user (see your first SSH session) and bring the system up to date with sudo apt update && sudo apt full-upgrade.
How do you install Nginx, PHP, MariaDB and Redis?
All of it comes from the distribution archive, and the unversioned package names pick the right PHP build on each release.
sudo apt install -y nginx mariadb-server redis-server unzip bzip2 \
php-fpm php-cli php-mysql php-gd php-curl php-mbstring php-intl \
php-xml php-zip php-bcmath php-gmp php-imagick php-apcu php-redis \
php-bz2 libmagickcore-6.q16-6-extra
php -v
ls /run/php/
sudo systemctl enable --now nginx mariadb redis-serverThe ls /run/php/ line shows the FPM socket name, for example php8.3-fpm.sock on Ubuntu 24.04. Note it; the Nginx config needs it. On Debian 13 the ImageMagick extras package may carry a different suffix, so run apt search libmagickcore and install the -extra package listed there, which adds SVG support for previews.
How do you prepare the database and PHP?
Create one database and one user for Nextcloud, then raise the PHP limits that the setup checks look for.
sudo mariadb-secure-installation
sudo mariadb
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'Change-This-Long-Passphrase';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;
EXIT;Next edit the FPM settings. Replace 8.3 with your version from the previous step.
PHPV=8.3
sudo sed -i 's/^memory_limit = .*/memory_limit = 512M/' /etc/php/$PHPV/fpm/php.ini
sudo sed -i 's/^upload_max_filesize = .*/upload_max_filesize = 1G/' /etc/php/$PHPV/fpm/php.ini
sudo sed -i 's/^post_max_size = .*/post_max_size = 1G/' /etc/php/$PHPV/fpm/php.ini
sudo sed -i 's/^;clear_env = no/clear_env = no/' /etc/php/$PHPV/fpm/pool.d/www.conf
echo 'opcache.interned_strings_buffer=16' | sudo tee /etc/php/$PHPV/mods-available/nc-opcache.ini
echo 'apc.enable_cli=1' | sudo tee -a /etc/php/$PHPV/mods-available/apcu.ini
sudo phpenmod nc-opcache
sudo systemctl restart php$PHPV-fpmThe apc.enable_cli line matters: without it, occ commands fail once APCu becomes the local cache. Also add the web user to the Redis group so it can use the socket later: sudo usermod -aG redis www-data.
How do you download and install Nextcloud?
Fetch the latest server archive, check its checksum, unpack it into the web root and run the installer from the command line.
cd /tmp
wget https://download.nextcloud.com/server/releases/latest.tar.bz2
wget https://download.nextcloud.com/server/releases/latest.tar.bz2.sha256
sha256sum -c latest.tar.bz2.sha256
sudo tar -xjf latest.tar.bz2 -C /var/www/
sudo mkdir -p /var/nc-data
sudo chown -R www-data:www-data /var/www/nextcloud /var/nc-data
cd /var/www/nextcloud
sudo -u www-data php occ maintenance:install \
--database mysql --database-name nextcloud \
--database-user nextcloud --database-pass 'Change-This-Long-Passphrase' \
--admin-user ncadmin --admin-pass 'Another-Long-Passphrase' \
--data-dir /var/nc-data
sudo -u www-data php occ config:system:set trusted_domains 1 --value=cloud.example.net
sudo -u www-data php occ statusKeeping the data directory outside /var/www means a web server mistake can never serve raw files. The last command prints the installed version and confirms installed: true.
What does the Nginx server block look like?
Nextcloud needs a fairly specific Nginx config: PHP handled by FPM, the DAV redirects, blocked internal folders and long uploads. Save this as /etc/nginx/sites-available/nextcloud and adjust the socket path.
upstream php-handler {
server unix:/run/php/php8.3-fpm.sock;
}
server {
listen 80;
listen [::]:80;
server_name cloud.example.net;
root /var/www/nextcloud;
index index.php index.html /index.php$request_uri;
client_max_body_size 1G;
client_body_timeout 300s;
client_body_buffer_size 512k;
fastcgi_buffers 64 4K;
include mime.types;
types { text/javascript js mjs; application/wasm wasm; }
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "noindex, nofollow" always;
fastcgi_hide_header X-Powered-By;
location = /robots.txt { allow all; log_not_found off; access_log off; }
location ^~ /.well-known {
location = /.well-known/carddav { return 301 /remote.php/dav/; }
location = /.well-known/caldav { return 301 /remote.php/dav/; }
location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
return 301 /index.php$request_uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
location ~ \.php(?:$|/) {
rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|ocs-provider\/.+) /index.php$request_uri;
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_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
fastcgi_max_temp_file_size 0;
}
location ~ \.(?:css|js|mjs|svg|gif|ico|jpg|png|webp|wasm|map|ogg|flac)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
access_log off;
}
location ~ \.woff2?$ { try_files $uri /index.php$request_uri; expires 7d; access_log off; }
location /remote { return 301 /remote.php$request_uri; }
location / { try_files $uri $uri/ /index.php$request_uri; }
}sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default
sudo nginx -t && sudo systemctl reload nginxCompare the block with the example in the Nextcloud admin manual for your release when you upgrade; new apps sometimes add paths to the rewrite list.
How do you add HTTPS and open the firewall?
Open ports 80 and 443, then let Certbot fetch a certificate and rewrite the server block for TLS with a redirect from plain HTTP.
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d cloud.example.net --redirect
curl -I https://cloud.example.net/status.phpThe status.php request should return 200 with JSON. Renewal runs from a systemd timer; confirm it with systemctl list-timers | grep certbot. If you prefer a different web front, the Certbot guide and firewall rules tutorial go into more depth.
How do you set up cron, caching and mail?
Run background jobs from system cron every five minutes, use APCu for the local cache and Redis for file locking, and send mail through an authenticated relay.
echo '*/5 * * * * php -f /var/www/nextcloud/cron.php' | sudo crontab -u www-data -
cd /var/www/nextcloud
sudo -u www-data php occ background:cron
sudo -u www-data php occ config:system:set memcache.local --value='\OC\Memcache\APCu'
sudo -u www-data php occ config:system:set memcache.locking --value='\OC\Memcache\Redis'
sudo -u www-data php occ config:system:set redis host --value=localhost
sudo -u www-data php occ config:system:set redis port --value=6379 --type=integer
sudo -u www-data php occ config:system:set maintenance_window_start --type=integer --value=1
sudo -u www-data php occ db:add-missing-indicesFor mail, open Administration settings, Basic settings, choose SMTP and enter your relay host, port 587 with STARTTLS and the account credentials, then press the test button. Outbound port 25 may be restricted, so open a support ticket before planning direct delivery from this server; the relay route on 587 works regardless, and sending app mail through an SMTP relay explains the setup.
How do you check the install and keep it updated?
The Overview page under Administration settings runs Nextcloud's own setup checks and lists anything missing, so start there after every change.
cd /var/www/nextcloud
sudo -u www-data php occ setupchecks
sudo -u www-data php occ app:update --all
sudo -u www-data php updater/updater.phar
sudo -u www-data php occ upgrade
sudo -u www-data php occ maintenance:mode --offThe updater moves you one major release at a time, which is the only supported path, so plan two runs if you fall two versions behind. Before each major step, put the instance in maintenance mode, dump the database and copy config/ and the data folder. The optional daily backup add-on adds a disk-level copy on top.
What should you check when something breaks?
Most problems show in the Nextcloud log, the PHP-FPM log or the Nginx error log, so read those three before changing settings.
- Trusted domain error: the host name is missing from
trusted_domainsinconfig/config.php. - 413 Request Entity Too Large: raise
client_max_body_sizeand the PHP upload limits together. - 502 Bad Gateway: the socket path in the upstream block does not match
ls /run/php/. - Redis locking errors:
redis-cli pingshould answer PONG.
sudo tail -n 50 /var/nc-data/nextcloud.log
sudo journalctl -u php8.3-fpm -n 50 --no-pager
sudo tail -n 50 /var/log/nginx/error.logPlans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
| Plan | Fits because | Size | Monthly | Order from |
|---|---|---|---|---|
| A2-4 | personal or family cloud with previews | 2 vCPU, 4 GB RAM, 100 GB NVMe | $14.40/mo | $43.20 for 3 months |
| A4-8 | small team with several sync clients | 4 vCPU, 8 GB RAM, 180 GB NVMe | $28.80/mo | $86.40 for 3 months |
| A8-16 | larger libraries and office add-ons | 8 vCPU, 16 GB RAM, 350 GB NVMe | $57.60/mo | $57.60 for 1 month |
Questions about Nextcloud on Nginx
Can I skip this setup and use a ready image?
Yes. Deploy the Nextcloud app image on Ubuntu 24.04; the web server, PHP and database are already installed and the admin details appear on the instance page in the console.
Should I use Nginx or Apache for Nextcloud?
Both are supported. Apache reads the bundled .htaccess rules, so it needs less manual config. Nginx needs the server block above but uses less memory per connection, which helps on small plans.
Where do my files live?
In the data directory you passed to the installer, /var/nc-data in this guide, on the local SSD or NVMe disk of your plan. External storage such as SFTP or WebDAV shares can be mounted through the External storage app.
How do I grow storage later?
Add-on volumes are not part of the offer, so deploy a plan with a bigger disk and move the instance across with the larger plan tutorial.
Is PostgreSQL better than MariaDB here?
Either works well. Pick the one you already know how to back up and tune. Switching later is possible with occ db:convert-type, but plan it during a quiet hour.
Do phone and desktop sync clients need anything special?
Only a valid HTTPS address and the CardDAV and CalDAV redirects in the Nginx block, which this guide already includes.
More in Self-hosted apps
- ownCloud Infinite Scale
- Seafile file sync
- Vaultwarden password vault
- Passbolt team password manager
- Gitea Git hosting
- Forgejo Git server
- GitLab Community Edition
- Gogs Git service
- Wiki.js
- BookStack documentation
- Outline knowledge base
- Paperless-ngx documents
- n8n workflow automation
- Activepieces automation
- Plausible Analytics (Community Edition)
- Umami analytics
- Mattermost team chat
- Matrix Synapse with Element
- Jitsi Meet video calls
- ONLYOFFICE Docs with Nextcloud
- HashiCorp Vault secrets server
- OpenBao secrets management
- Infisical secrets manager
- Authelia SSO and forward auth
- Zitadel identity platform
- VS Code in the browser (code-server)
- Joplin Server for notes sync
- Firefly III personal finance
- Snipe-IT asset tracking
- Odoo ERP on Ubuntu or Debian
- ERPNext with frappe_docker
- Dolibarr ERP and CRM with Nginx
- Penpot design tool with Docker
- Planka kanban boards
- Leantime project management
- Wekan boards with Docker
- Cal.com scheduling
- Chatwoot support inbox
- Mautic marketing automation
- DocuSeal document signing
- Metabase dashboards
- Appwrite backend server
- Self-hosted Supabase
- PocketBase backend
- RustDesk relay server
- Traccar GPS tracking
- Redmine project tracker
- The Lounge IRC client
- CyberChef data toolbox
- Typebot chat forms
- AFFiNE workspace
- Overleaf Community Edition
- Neko shared virtual browser
- imgproxy image resizing
- NetBox network inventory
- UVdesk help desk
- YetiForce CRM