- Overview
- Why you should optimize your Nextcloud server
- Increase PHP upload limit and adjust timeouts
- Nextcloud performance tweaks with APCu and Opcache
- Enable Cronjob and configure background jobs
- Optimize Nextcloud config.php
- Important occ commands for maintenance and performance
- Do not forget database, storage and network
- Database tuning
- Storage and file system
- Network and reverse proxy
- Conclusion: optimizing your Nextcloud server is more than just raising the upload limit
Why you should optimize your Nextcloud server
Nextcloud is more than just a pretty network drive. If you use your Nextcloud server as the central hub for your files and workflows, you quickly notice how important performance and stability are. Large uploads fail, downloads run into timeouts, the web interface feels sluggish and previews of photos or videos load painfully slow.
In this article I will show you how to optimize your Nextcloud server, improve performance and adjust typical limits such as the PHP upload limit and timeouts. On top of that we will look at how to enable Cronjobs, how to tune the Nextcloud config.php and which commands are really useful for maintenance and tuning.
The examples are based on a setup with Ubuntu, Apache and PHP 8.3 or 8.4. Many of the tips also apply if you use PHP-FPM or Nginx instead of Apache.
Increase PHP upload limit and adjust timeouts
To upload large files reliably in Nextcloud, several PHP parameters must work together. On Ubuntu with Apache and PHP 8.4 you usually edit:
sudo nano /etc/php/8.4/apache2/php.ini
Important settings for uploads and timeouts:
| Setting | Example value | Effect |
|---|---|---|
memory_limit | 1024M or 2G | Maximum RAM per PHP process |
upload_max_filesize | 8G | Maximum size of a single uploaded file |
post_max_size | 8G or larger | Maximum size of the entire POST request |
max_file_uploads | 200 | How many files can be uploaded per request |
default_socket_timeout | 900 | Timeout in seconds for streams, for example slow uploads |
A few rules of thumb:
post_max_sizeshould be at least as large asupload_max_filesize, ideally slightly larger.- Do not use absurd values like
256Gif your server only has 16 GB RAM and 2 TB of storage. Adapt the values to your real hardware and use case. - For very large files the timeout is often the real problem. Increase these values as well:
max_execution_timeto for example3600max_input_timeto for example3600
Example snippet from a php.ini file:
memory_limit = 2G
upload_max_filesize = 8G
post_max_size = 8G
max_file_uploads = 200
max_execution_time = 3600
max_input_time = 3600
default_socket_timeout = 900
zlib.output_compression = On
zlib.output_compression_level = 6
The zlib.output_compression setting can help to reduce the response size, especially on slower connections. Just make sure that your reverse proxy or web server does not compress the same response a second time.
If you use Nginx or a reverse proxy in front of Apache, you also have to adjust upload and timeout limits there, for example:
- Nginx:
client_max_body_size - Apache:
LimitRequestBodyand timeouts such asProxyTimeoutorRequestReadTimeout
If one of these limits is too low, large Nextcloud uploads will still fail even if the PHP upload limit looks correct.
Nextcloud performance tweaks with APCu and Opcache
Nextcloud performance improves a lot if you configure PHP Opcache and a local cache like APCu.
In your php.ini or a dedicated apcu.ini you can enable APCu like this:
apc.enabled=1
apc.shm_segments=1
apc.shm_size=256M
apc.entries_hint=8192
Values like apc.shm_size=768M from your notes are fine for large installations with many users. For a small private Nextcloud server 128M to 256M is usually enough.
PHP Opcache stores compiled PHP scripts in memory so that they do not need to be parsed over and over again:
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=256
opcache.interned_strings_buffer=32
opcache.max_accelerated_files=20000
opcache.max_wasted_percentage=10
In simple terms:
opcache.memory_consumptiondefines how much RAM Opcache may use. 128 to 256 MB is a good starting point for many Nextcloud servers.opcache.max_accelerated_filescontrols how many PHP files can be cached. Values between 10000 and 20000 work well for typical Nextcloud setups.
After changing PHP settings you must restart Apache or PHP-FPM:
sudo systemctl restart apache2
# or
sudo systemctl restart php8.4-fpm
Without APCu and Opcache your Nextcloud server will work, but the web interface feels noticeably slower, especially with multiple users.
Enable Cronjob and configure background jobs
Nextcloud runs many tasks in the background: generating previews, cleaning up old shares, syncing external storage, updating the file cache and much more. By default this runs via AJAX which is easy to set up but bad for performance, because jobs only start when someone is active in the browser.
It is better to switch to a system Cronjob. Open the Nextcloud admin settings, go to “Basic settings” and change “Background jobs” to “Cron”.
Then create a Cronjob as the www-data user:
sudo -u www-data crontab -e
For example:
*/5 * * * * php --define apc.enable_cli=1 -f /var/www/html/cron.php > /dev/null 2>&1
Now the Nextcloud Cron runs every 5 minutes, independent of user activity in the web interface.
In your notes you also use extra maintenance jobs with occ files:scan to rescan specific user folders or external storage. That is absolutely fine, but try not to run full scans too often. A nightly targeted scan for critical paths is usually enough, otherwise you will put unnecessary load on your database.
Optimize Nextcloud config.php
The file config/config.php controls many internal Nextcloud functions. On a standard installation you edit it like this:
nano /var/www/html/config/config.php
Some of your entries and what they do:
'memcache.local' => '\\OC\\Memcache\\APCu',
'preview_max_memory' => 4096,
'versions_retention_obligation' => '5,auto',
'trashbin_retention_obligation' => '5,auto',
'filelocking.enabled' => false,
'check_data_directory_permissions' => false,
'files.chunked_upload.max_size' => 20971520,
'enabledPreviewProviders' => array(
'OC\\Preview\\PNG',
'OC\\Preview\\JPEG',
'OC\\Preview\\GIF',
'OC\\Preview\\HEIC',
'OC\\Preview\\BMP',
'OC\\Preview\\XBitmap',
'OC\\Preview\\MP3',
'OC\\Preview\\TXT',
'OC\\Preview\\MarkDown',
'OC\\Preview\\OpenDocument',
'OC\\Preview\\Krita',
'OC\\Preview\\PDF',
'OC\\Preview\\SVG',
'OC\\Preview\\EPS',
'OC\\Preview\\DOC',
'OC\\Preview\\DOCX',
'OC\\Preview\\TIFF',
'OC\\Preview\\Photoshop',
'OC\\Preview\\PhotoshopPSB',
'OC\\Preview\\MP4',
),
Short summary:
memcache.localwith APCu is essential for performance. Without it, Nextcloud will feel very slow.preview_max_memorylimits the RAM used to generate previews. The default is much smaller, 4096 MB is quite generous. Adjust the value to match your hardware.versions_retention_obligationandtrashbin_retention_obligationcontrol how long versions and trashbin contents are kept. Shorter retention saves disk space but reduces restore options.files.chunked_upload.max_sizecontrols the chunk size for uploads in bytes.20971520equals 20 MB. Larger chunks can help on fast connections but are more sensitive to unstable networks.
Be careful with:
'filelocking.enabled' => false,
'check_data_directory_permissions' => false,
- You should only disable
filelocking.enabledif you really know what you are doing. A better approach is to configure Redis asmemcache.lockingso that concurrent access to files is handled safely. check_data_directory_permissionsset tofalsecan make sense in special setups but you also lose a security check that warns you about wrong permissions.
Important occ commands for maintenance and performance
The Nextcloud CLI tool occ is extremely helpful for maintenance tasks and tuning. You usually run commands like this:
sudo -u www-data php /var/www/html/occ status
Some useful commands:
occ status
Shows basic information about your Nextcloud instance.occ db:add-missing-indices
Adds missing database indexes and can speed up many queries.occ db:convert-filecache-bigint
Converts columns in the database to more suitable types for better performance and stability.occ files:scan --allor with--path
Rescans the file system and updates the file cache. Very useful if files appear on the disk but not in Nextcloud. Do not run full scans every hour, it is heavy on the database.occ preview:pre-generate
Together with the Preview Generator app you can pre-generate previews at night so that users see images and PDFs much faster in the web interface.
These occ commands are an important part of long term Nextcloud server optimization, especially if your instance grows over time.
Do not forget database, storage and network
If you really want to optimize your Nextcloud server, you should also look beyond PHP and config files.
Database tuning
- Use MariaDB or PostgreSQL if possible.
- Make sure the buffer pool is large enough, for example:
- MariaDB: set
innodb_buffer_pool_sizeto 1 or 2 GB on small servers.
- MariaDB: set
- Enable regular backups and check logs for slow queries from time to time.
Storage and file system
- SSD or NVMe drives offer a huge performance boost compared to old spinning HDDs.
- With many small files it can be worth looking at the file system and mount options to reduce latency.
- External storage (SMB, NFS) is convenient, but usually slower than local storage. Plan this into your performance expectations.
Network and reverse proxy
- Make sure your Internet connection can handle your upload needs, especially if many users work remotely with large files.
- Check timeouts and body limits on your reverse proxy (Nginx, Traefik, Apache Proxy).
- Enable HTTP/2 or HTTP/3 if your setup supports it to handle many small requests more efficiently.

