How to Improve Nextcloud Photos Performance
Improving photo performance in Nextcloud is one of the most impactful upgrades you can make, as the default behavior tends to render images lazily (on-demand), which completely chokes the system when you try to scroll through a timeline.
To transform it from sluggish to snappy, you need to tackle preview pre-generation, database/memory caching, and consider a high-performance alternative frontend.
1. The Game Changer: Use the “Preview Generator” App
By default, Nextcloud generates thumbnails on the fly as you scroll. To fix this, download the Preview Generator app from the Nextcloud App Store, which forces Nextcloud to generate previews in the background.
Step A: Restrict Preview Sizes (Crucial for Storage)
Before generating anything, prevent Nextcloud from creating massive, unnecessary thumbnail sizes that eat up your storage. SSH into your server and run these occ commands (adjust sudo -u www-data php based on your setup):
sudo -u www-data php occ config:app:set --value="32 256" previewgenerator squareSizes sudo -u www-data php occ config:app:set --value="256 384" previewgenerator widthSizes sudo -u www-data php occ config:app:set --value="256" previewgenerator heightSizes
Next, open your config/config.php file and add or edit these lines to cap the resolution and quality:
'preview_max_x' => '2048', 'preview_max_y' => '2048', 'jpeg_quality' => '60', 'preview_format' => 'webp', // WebP is faster to load and smaller than JPEG
Step B: Generate the Initial Previews
Run the initial generation script. Note: If you have tens of thousands of photos, run this overnight as it will heavily utilize your CPU.
sudo -u www-data php occ preview:generate-all -vvv
Step C: Automate It with a Cron Job
To make sure new uploads get pre-generated instantly, add the pre-generate task to your web server’s crontab (sudo -u www-data crontab -e):
*/10 * * * * php -f /var/www/nextcloud/occ preview:pre-generate
2. Offload Preview Generation to “Imaginary”
If your CPU is constantly pinned while processing photos, swap Nextcloud’s built-in PHP GD/Imagick processor for Imaginary—a lightweight, lightning-fast image processing microservice.
-
Run an Imaginary container via Docker.
- Link it in your
config.php:'preview_service_provider' => '\OC\Preview\Imaginary', 'preview_imaginary_url' => 'http://your-imaginary-container-ip:9000',
This completely un-ties image resizing from your PHP workers, leaving them free to handle user interface requests.
3. Boost Underlying Server Performance
A fast photo gallery relies heavily on quick database queries and memory mapping.
- Switch to System Cron: In the Nextcloud settings under Basic Settings, make sure Background Jobs are set to Cron, not AJAX or Webcron. Then ensure your system crontab runs Nextcloud’s
cron.phpevery 5 minutes. -
Enable Memory Caching (Redis + APCu): Ensure your
config.phputilizes APCu for local cache and Redis for distributed cache and file locking. Running file-locking through Redis prevents the database from locking up when loading hundreds of image files at once. - Optimize PHP-FPM: If you are managing your own PHP installation, increase the
memory_limitin yourphp.inito at least512Mor1G. Tune your PHP-FPM pool (max_children,start_servers) so your server can handle simultaneous asset requests. - Switch to PostgreSQL: Nextcloud runs much faster with PostgreSQL, especially on large instance.
4. The Nuclear Option: Install “Memories”
If you have done all of the above and the default Nextcloud Photos app still feels clunky, install Memories from the Nextcloud App Store.
Memories is a drop-in replacement frontend for your Nextcloud photo collection. It is highly optimized, features a timeline layout that handles hundreds of thousands of photos seamlessly (similar to Google Photos or Immich), and runs significantly faster than the default Photos application because it bypasses many of Nextcloud’s heavy filesystem abstractions during rendering.


