Guide to Self-Hosting Immich on VPS with Cloudflare R2: Unlimited Photo Backup Solution
A detailed guide to self-hosting Immich on a VPS combined with Cloudflare R2 for unlimited photo backup, replacing Google Photos. Covers setup, configuration, testing, and...
Self-Hosting Immich on VPS: Unlimited Photo Backup Solution
Immich is a self-hosted photo and video storage platform that lets you fully control your data without relying on cloud services like Google Photos. By combining Immich with a VPS and Cloudflare R2, you can build a low-cost, secure, and unlimited photo backup system. This guide walks you through every step of deploying this solution.
Requirements and Preparation
To deploy Immich on a VPS with Cloudflare R2, you need:
- A VPS with at least 4GB RAM and 20GB SSD (recommended 8GB RAM for large photo collections)
- A public IP address and SSH access
- A Cloudflare account (free registration available)
- Cloudflare R2 API key and Zone ID
- A custom domain (HTTPS recommended)
Install Immich on VPS
Follow these steps to install Immich using Docker:
sudo apt update
sudo apt install docker.io docker-compose -y
git clone https://github.com/immich-app/immich.git
cd immich
cp .env.example .env
Modify the .env file to configure:
IMMICH_MODE=production
IMMICH_STORAGE_TYPE=cloudflare-r2
IMMICH_CLOUDFLARE_R2_ACCESS_KEY_ID=YOUR_CLOUDFLARE_R2_ACCESS_KEY
IMMICH_CLOUDFLARE_R2_SECRET_ACCESS_KEY=YOUR_CLOUDFLARE_R2_SECRET_KEY
IMMICH_CLOUDFLARE_R2_BUCKET_NAME=your-bucket-name
IMMICH_CLOUDFLARE_R2_REGION=auto
IMMICH_CLOUDFLARE_R2_ENDPOINT=https://your-bucket-name.r2.cloudflarestorage.com
Create a new bucket in Cloudflare R2 via the dashboard. Enable \"Public Access\" if you need public access.
Connect to Cloudflare R2
Cloudflare R2 is an S3-compatible object storage service with a free tier of 10GB. To connect Immich to R2:
- Log in to your Cloudflare Dashboard
- Go to \"R2\" in the left menu
- Create a new bucket (e.g.,
immich-backup) - Generate an Access Key and Secret Key (save them securely)
- Copy the Zone ID from the R2 dashboard
In the Immich .env file, update the environment variables as shown. Ensure the endpoint follows the format: https://[bucket-name].r2.cloudflarestorage.com.
Start and Verify
Launch Immich using Docker Compose:
docker-compose up -d
After startup, access https://your-domain.com to log in. If you don’t have a domain, use your IP or localhost for internal testing.
To verify the R2 connection:
docker logs immich-server
Wait a few minutes for Immich to download sample images and check if they appear in your R2 bucket.
Troubleshooting
- Cannot connect to R2: Double-check the Access Key, Secret Key, and endpoint. Ensure the bucket exists and permissions are correct.
- Images fail to upload: Check Immich logs for S3 errors. Review the
.envconfiguration. - HTTPS not working: If using a domain, ensure SSL is configured via Cloudflare or Let's Encrypt.
Alternative to Google Photos
Immich offers features similar to Google Photos, including:
- Automatic photo upload from mobile devices
- Search by date, location, and people
- Public or private sharing
- Data redundancy through distributed storage
Compared to Google Photos, Immich gives you full data control, no storage limits, and stronger privacy protection.
References
- Official Immich Documentation
- Cloudflare R2 Documentation
- Building an S3-Compatible Object Storage System with GarageHQ
Related infrastructure & engineering guides: High-RAM Cloud VPS for Self-Hosted LLMs & API Gateways
High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-4E
10% VAT included
- CPU: 4 vCPU
- RAM: 8 GB
- SSD: 50 GB NVMe
