Oct 25, 2024 3 min read

Librephotos: Self-Hosting Made Simple

Librephotos: Self-Hosting Made Simple
Table of Contents

Librephotos is an open-source, self-hosted photo management solution designed to help individuals and organizations organize, archive, and share their photo libraries securely. Unlike proprietary cloud-based photo apps, Librephotos offers full control over your data, ensuring privacy and the ability to customize the app to fit your specific needs. This guide will take you through installing, configuring, securing, and managing Librephotos, ensuring a smooth deployment for developers and advanced users.

Installing Librephotos

πŸ“¦ Docker/Docker Compose Setup

Docker is the recommended way to run Librephotos. Below is a docker-compose.yml file tailored to Librephotos, including settings for persistent storage and environment variables.

Create a docker-compose.yml file using the following content:


version: '3.4'

services:

librephotos-backend:

image: reallibrephotos/librephotos:latest

container_name: librephotos-backend

restart: unless-stopped

environment:

- SECRET_KEY=your_secret_key_here

- DB_BACKEND=postgresql

- DB_NAME=librephotos

- DB_USER=librephotos_user

- DB_PASSWORD=secure_password_here

- DB_HOST=librephotos-db

- TIMEZONE=UTC

ports:

- "8000:8000"

volumes:

- ./data:/data

- ./cache:/cache

librephotos-frontend:

image: reallibrephotos/librephotos-frontend:latest

container_name: librephotos-frontend

restart: unless-stopped

ports:

- "3000:80"

librephotos-db:

image: postgres:13

container_name: librephotos-db

restart: unless-stopped

environment:

POSTGRES_USER: librephotos_user

POSTGRES_PASSWORD: secure_password_here

POSTGRES_DB: librephotos

volumes:

- ./db:/var/lib/postgresql/data

Run the following commands to deploy the application:


cd /path/to/librephotos

## Start the services

docker-compose up -d

Verify that the backend is accessible on http://<your_server_ip>:8000 and the frontend on http://<your_server_ip>:3000.

πŸš€ Manual Installation

For advanced users, a manual installation allows greater customization. Below are the steps for setting up Librephotos on a Linux server:

  1. Install Dependencies:

sudo apt update

sudo apt install -y python3 python3-pip git postgresql redis

  1. Clone the Repository and Install the Backend:

git clone https://github.com/LibrePhotos/librephotos.git

cd librephotos

pip3 install -r requirements.txt

python3 manage.py migrate

python3 manage.py runserver 0.0.0.0:8000

  1. Set Up the Frontend:

## Navigate to the frontend directory

cd frontend

npm install

npm run build

npm start

Adjust the commands to fit your server environment and network configuration.

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

Nginx can serve as a reverse proxy for routing traffic to Librephotos. Create a new configuration file for Librephotos:


sudo nano /etc/nginx/sites-available/librephotos

Add the following content:


server {

listen 80;

server_name your_domain_or_ip;

location / {

proxy_pass http://127.0.0.1:8000;

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 and restart Nginx:


sudo ln -s /etc/nginx/sites-available/librephotos /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl restart nginx

πŸ”’ SSL/TLS Setup

To secure the app, use Let's Encrypt:


sudo apt install certbot python3-certbot-nginx

sudo certbot --nginx -d your_domain_or_ip

Enable automatic renewal:


sudo crontab -e

## Add the following line

0 0 * * * certbot renew --quiet

Logging and Debugging Librephotos

πŸ—ƒοΈ Enabling Debug Logs

To enable debug-level logging, edit the settings.py file in Librephotos:


nano settings.py

Set the logging level to debug:


LOGGING = {

'version': 1,

'handlers': {

'console': {

'class': 'logging.StreamHandler',

},

},

'root': {

'handlers': ['console'],

'level': 'DEBUG',

},

}

Restart the application to apply changes.

πŸ“„ Viewing Logs

For Docker deployments, view logs with:


docker logs librephotos-backend

For manual installations:


tail -f /var/log/librephotos.log

πŸ› οΈ Troubleshooting Common Issues

Check common errors such as database connection issues (DB_HOST misconfiguration) or missing environment variables. Use logs to pinpoint and resolve problems.

Backup and Restore

πŸ—‚οΈ File-Based Backups

Backup the application data directory:


tar -czvf librephotos-data-backup.tar.gz /path/to/librephotos/data

πŸ”„ Database Backups

Export the PostgreSQL database:


pg_dump -U librephotos_user -h localhost librephotos > librephotos_db_backup.sql

Restore the database:


psql -U librephotos_user -h localhost librephotos < librephotos_db_backup.sql

πŸ“… Automated Backup Scripts

Create a cron job to automate backups:


crontab -e

## Add the following line (runs daily at midnight)

0 0 * * * tar -czvf /path/to/backup_$(date +\%F).tar.gz /path/to/librephotos/data

Updating and Upgrading Librephotos

⬆️ Updating Docker Images

To update Librephotos with Docker:


docker-compose pull

docker-compose up -d

πŸ› οΈ Manual Updates

For a manual installation, pull the latest source code and re-run migrations:


cd /path/to/librephotos

git pull

python3 manage.py migrate

πŸ” Checking for Updates

Regularly check Librephotos’s GitHub repository for new releases or changelogs.

Leveraging Librephotos’s Unique Features

πŸ”§ Enabling APIs

Librephotos provides an API for advanced integrations. Enable the API in your backend settings and use a tool like curl to test endpoints:


curl -X GET http://127.0.0.1:8000/api/photos -H "Authorization: Token your_api_token"

🌟 Advanced Configurations

Customize photo categorization, face recognition, or third-party integrations by editing Librephotos configuration files in the backend directory. Consult the official documentation for available options.

Wrapping Up

Librephotos empowers you to take full control of your photo library while ensuring data privacy and scalability. By following this guide, you’ve learned how to deploy, configure, and manage Librephotos effectively. Start exploring its features and take your photo management to the next level!

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.