Oct 20, 2024 3 min read

Immich: Self-Hosting Made Simple

Immich: Self-Hosting Made Simple
Table of Contents

Immich is an open-source, self-hosted photo and video backup solution designed for tech-savvy users who prioritize privacy, customization, and full control over their data. With features like automatic uploads, deduplication, and seamless media organization, it’s a powerful alternative to traditional cloud-based services. This guide will take you through the steps to install, configure, and manage Immich, ensuring you have a robust setup for securely hosting your media.

Installing Immich

πŸ“¦ Docker/Docker Compose Setup

Immich is best deployed using Docker for ease of management and portability. Below is a docker-compose.yml file tailored for Immich, along with commands to bring the app online.

Create a docker-compose.yml file:


version: '3.8'

services:

immich-server:

image: ghcr.io/immich-app/immich-server:latest

container_name: immich-server

environment:

- IMMICH_DATABASE_URL=postgresql://postgres:password@immich-db/immich

- IMMICH_REDIS_URL=redis://immich-redis:6379

ports:

- "3001:3001"

depends_on:

- immich-db

- immich-redis

restart: unless-stopped

immich-web:

image: ghcr.io/immich-app/immich-web:latest

container_name: immich-web

ports:

- "8080:80"

depends_on:

- immich-server

restart: unless-stopped

immich-db:

image: postgres:14

container_name: immich-db

environment:

- POSTGRES_USER=postgres

- POSTGRES_PASSWORD=password

volumes:

- immich_db_data:/var/lib/postgresql/data

restart: unless-stopped

immich-redis:

image: redis:6

container_name: immich-redis

restart: unless-stopped

volumes:

immich_db_data:

Start the containers:


docker-compose up -d

Check the status of the services:


docker ps

πŸš€ Manual Installation

If you prefer not to use Docker, you can manually install Immich on a Linux server. Here's how:

  1. Install dependencies:

sudo apt update && sudo apt install -y nodejs npm postgresql redis git

  1. Clone the Immich repository:

git clone https://github.com/immich-app/immich.git

cd immich

  1. Start the backend and frontend:

cd server

npm install

npm run start:prod

cd ../web

npm install

npm run start

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

Use Nginx to route traffic to Immich and serve the application securely. Create a server block file at /etc/nginx/sites-available/immich.conf:


server {

listen 80;

server_name yourdomain.com;

location / {

proxy_pass http://localhost:8080; # Immich Web

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

location /api/ {

proxy_pass http://localhost:3001; # Immich API

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

Enable the configuration:


sudo ln -s /etc/nginx/sites-available/immich.conf /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl reload nginx

πŸ”’ SSL/TLS Setup

Secure your Immich instance using Let's Encrypt:


sudo apt install -y certbot python3-certbot-nginx

sudo certbot --nginx -d yourdomain.com

Automate certificate renewals:


sudo systemctl enable certbot.timer

sudo systemctl start certbot.timer

πŸ› οΈ Testing and Reloading Nginx

To verify that Nginx is set up correctly:


sudo nginx -t

sudo systemctl reload nginx

Logging and Debugging Immich

πŸ—ƒοΈ Enabling Debug Logs

To enable debug-level logs, modify the IMMICH_LOG_LEVEL environment variable in your docker-compose.yml:


environment:

- IMMICH_LOG_LEVEL=debug

Restart the containers:


docker-compose restart

πŸ“„ Viewing Logs

For Docker-based installations, check logs with:


docker logs immich-server

docker logs immich-web

For manual setups, check logs in the output of the Node.js processes.

πŸ› οΈ Troubleshooting Common Issues

If you encounter errors, search for key terms in the logs. Example:


docker logs immich-server | grep "error"

πŸ“€ Exporting Logs

To centralize logs, use a script to send them to an ELK Stack:


docker logs immich-server > immich-server.log

scp immich-server.log user@elk-stack-server:/path/to/logs/

Backup and Restore

πŸ—‚οΈ File-Based Backups

Backup your Immich data and configuration:


tar -czvf immich-backup.tar.gz /path/to/immich_data

πŸ”„ Database Backups

Dump the PostgreSQL database:


docker exec -t immich-db pg_dumpall -c -U postgres > immich-db-backup.sql

To restore:


docker exec -i immich-db psql -U postgres -f immich-db-backup.sql

πŸ“… Automated Backup Scripts

Automate backups with a cron job:


0 3 * * * tar -czvf /path/to/backups/immich-$(date +\%F).tar.gz /path/to/immich_data

Updating and Upgrading Immich

⬆️ Updating Docker Images

Update Immich to the latest version:


docker-compose pull

docker-compose up -d

πŸ› οΈ Manual Updates

For manual setups, pull the latest code:


cd immich

git pull

cd server && npm install && npm run build

cd ../web && npm install && npm run build

Restart the services:


pm2 restart immich-server immich-web

πŸ” Checking for Updates

Monitor Immich’s GitHub repository for new releases:


git fetch --tags

Leveraging Immich’s Unique Features

πŸ”§ Enabling APIs

Enable Immich’s API functionality by ensuring the backend is running. Test with:


curl http://localhost:3001/api/alive

🌟 Advanced Configurations

Customize Immich’s behavior by modifying environment variables in your docker-compose.yml file. For example:


environment:

- IMMICH_UPLOAD_MAX_FILE_SIZE=100MB

Restart the containers to apply changes:


docker-compose restart

Wrapping Up

By following this guide, you’ve successfully deployed, secured, and configured Immich to host your media files with full control and privacy. With powerful features and extensive customization, Immich empowers you to move away from proprietary cloud solutions. Start leveraging the provided examples to fully unlock the potential of Immich in your environment!

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.