Nextcloud best practices
Performance and stability best practices for Nextcloud on TurboStack, covering required Redis caching and file locking, OPcache, background cron, large uploads and safe scaling.
Reliable Nextcloud performance depends on the right cache layers, a tuned PHP runtime, and healthy background jobs. On TurboStack, most of this is configured when you deploy a nextcloud app, so your main effort is keeping caching healthy and following Nextcloud's own production guidance. This page covers what the platform configures and the optimizations to layer on top.
What TurboStack configures for you
When you deploy Nextcloud, TurboStack provisions a working, production-shaped stack:
- Nginx vhost tuned for Nextcloud - the document root is set to
public_html. Standard Nextcloud rewrites andlocationblocks are in place: front-controller routing throughindex.php,.well-knownredirects for CalDAV/CardDAV (calendar and contacts), anddenyrules fordata,config,lib,3rdparty,occ, and similar paths. Security headers are added,X-Powered-Byis hidden, and static assets are served with long-livedCache-Control. - PHP-FPM backend per site - PHP requests are passed to a dedicated FastCGI pool, with
fastcgi_request_buffering offandHTTPS onset so large uploads and DAV requests behave correctly. DAV is short for Distributed Authoring and Versioning, the WebDAV protocol behind CalDAV and CardDAV. - Redis (required) - installed and configured in
config.phpover a unix socket (/var/run/redis/redis.sock). It is configured for transactional file locking (memcache.locking = \OC\Memcache\Redis), with APCu (memcache.local = \OC\Memcache\APCu) as the local memory cache. - config.php essentials -
trusted_domainsis populated with your server name, FQDN, and host IP.overwrite.cli.url,mysql.utf8mb4, and theproductionupdater channel are set viaocc config:system:set. - Database - a dedicated MySQL/MariaDB (or PostgreSQL) database and user are created and Nextcloud is installed against it with
occ maintenance:install. - Transport Layer Security (TLS) and large uploads - TLS is provisioned (Let's Encrypt or your own certificate). The upload ceiling is driven by
nextcloud_max_upload_size(default512m), which also sets the PHP and web-server limits. - Hardened data permissions - the data directory is created outside the web root, owned by the system user, with directories at
0750and files at0640.
Recommended optimizations
- Keep Redis healthy - Redis is mandatory for transactional file locking and the memory cache. Confirm it is running as a service and monitor its memory so locks do not revert to the database.
- Use system cron for background jobs - set the background job mode to Cron (
occ background:job:mode cron). A system scheduler then runscron.phpevery 5 minutes, which is faster and more reliable than the AJAX (Asynchronous JavaScript and XML) or webcron modes (nextcloud_background_cron). - OPcache - the PHP runtime ships with OPcache; keep it enabled (with a generous
interned_strings_bufferandmemory_consumption) so compiled PHP is reused across requests. - Add full-text search (optional) - for large libraries, install the Full Text Search apps backed by Elasticsearch/OpenSearch so document search stays fast.
- Raise upload limits deliberately - increase
nextcloud_max_upload_size(and the matching PHPupload_max_filesize/post_max_size) when users sync large files; avoid setting it far higher than needed. - Run "Add missing indices" - after upgrades, run
occ db:add-missing-indicesand clear the admin overview warnings to keep queries efficient. - Front media with a Content Delivery Network (CDN) - serve static assets through an HTTP cache/CDN to cut origin load and improve global latency.
Sizing and scaling
Defaults are auto-tuned to the host, so do not pre-emptively raise them. Override sizing variables only with measured evidence (slow queries, cache evictions, swap):
See Performance tuning for the full method: measure, change one variable, re-measure.
Stability
- Back up regularly - keep automated Backups of the database and the data directory; test a restore before you need one.
- Watch the host - monitor the Health tab for CPU, memory, disk, and service alerts. A full data disk takes Nextcloud offline.
- Stay current - keep Nextcloud, its apps and the PHP runtime on supported versions; apply upgrades through the built-in updater (pinned to the
productionchannel) during quiet windows. - Test on a staging clone - validate major upgrades and app changes on a copy of the host before touching production.