Lemmy is a powerful, open-source link aggregator and discussion platform, often compared to Reddit but designed with decentralization and federation in mind. Self-hosting Lemmy offers complete control over your data, customization options, and the ability to participate in the broader Fediverse. In this guide, weβll walk through how to deploy, configure, and manage a self-hosted Lemmy instance, including setting up a reverse proxy, enabling logging, backing up data, and staying updated.
Installing Lemmy
π¦ Docker/Docker Compose Setup
Docker is the recommended way to deploy Lemmy, as it simplifies dependency and service management. Below is an example docker-compose.yml
file tailored for Lemmy.
Create a docker-compose.yml
file:
version: "3.7"
services:
postgres:
image: postgres:15
container_name: lemmy_postgres
environment:
POSTGRES_USER: lemmy
POSTGRES_PASSWORD: password
POSTGRES_DB: lemmy
volumes:
- postgres_data:/var/lib/postgresql/data
restart: always
lemmy:
image: dessalines/lemmy:latest
container_name: lemmy
environment:
LEMMY_EXTERNAL_HOST: "example.com"
LEMMY_HTTPS: "true"
LEMMY_POSTGRES_USER: "lemmy"
LEMMY_POSTGRES_PASSWORD: "password"
LEMMY_POSTGRES_HOST: "postgres"
ports:
- "127.0.0.1:8536:8536"
depends_on:
- postgres
volumes:
- lemmy_data:/lemmy/data
restart: always
volumes:
postgres_data:
lemmy_data:
Deploy the containers:
docker-compose up -d
Verify the containers are running:
docker ps
π Manual Installation
For advanced users preferring a manual setup, follow these steps on a Linux server.
Install dependencies:
sudo apt update && sudo apt install -y postgresql cargo build-essential libssl-dev
Clone and build Lemmy:
git clone https://github.com/LemmyNet/lemmy.git
cd lemmy
cargo build --release
Set up the database:
sudo -u postgres psql -c "CREATE USER lemmy WITH PASSWORD 'password';"
sudo -u postgres psql -c "CREATE DATABASE lemmy OWNER lemmy;"
Run Lemmy:
./target/release/lemmy --config ./lemmy.hjson
Configuring Nginx as a Reverse Proxy
π Nginx Configuration
Nginx helps route incoming HTTP traffic to Lemmy. Create an Nginx server block file, e.g., /etc/nginx/sites-available/lemmy
:
server {
server_name example.com;
location / {
proxy_pass http://127.0.0.1:8536;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
listen 80;
}
Enable the configuration:
ln -s /etc/nginx/sites-available/lemmy /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
π SSL/TLS Setup
Secure your instance with Letβs Encrypt SSL certificates and Certbot.
Install Certbot:
sudo apt install -y certbot python3-certbot-nginx
Obtain and configure SSL:
sudo certbot --nginx -d example.com
Automate renewals:
sudo systemctl enable certbot.timer
Logging and Debugging Lemmy
ποΈ Enabling Debug Logs
To enable debug-level logging, modify the Lemmy configuration file (e.g., lemmy.hjson
) and set the appropriate logging level:
logging: {
level: "debug"
file: "/lemmy/data/lemmy.log"
}
Restart Lemmy to apply changes:
docker-compose restart lemmy
π Viewing Logs
For Docker deployments:
docker logs lemmy -f
For manual installations:
tail -f /lemmy/data/lemmy.log
π οΈ Troubleshooting Common Issues
-
If Lemmy fails to start, check database connectivity.
-
Verify environment variables in Docker or configuration settings for typos.
-
Use
curl -I http://127.0.0.1:8536
to confirm Lemmyβs internal service is running.
Backup and Restore
ποΈ File-Based Backups
Backup Lemmy data and configurations:
tar -czvf lemmy_backup_$(date +%F).tar.gz /path/to/lemmy/data
π Database Backups
To back up the database:
docker exec lemmy_postgres pg_dump -U lemmy lemmy > lemmy_db_backup.sql
Restore the database:
docker exec -i lemmy_postgres psql -U lemmy lemmy < lemmy_db_backup.sql
π Automated Backup Scripts
Automate backups with cron:
echo "0 3 * * * /usr/bin/docker exec lemmy_postgres pg_dump -U lemmy lemmy > /backups/lemmy_db_backup_$(date +\%F).sql" | crontab -
Updating and Upgrading Lemmy
β¬οΈ Updating Docker Images
Pull the latest image and redeploy:
docker-compose down
docker-compose pull
docker-compose up -d
π οΈ Manual Updates
Rebuild Lemmy with the latest code:
git pull
cargo build --release
Restart the application:
./target/release/lemmy --config ./lemmy.hjson
π Checking for Updates
Monitor Lemmyβs GitHub repository for release notes and new updates:
git fetch && git log HEAD..origin/main --oneline
Leveraging Lemmyβs Unique Features
π§ Enabling APIs
Lemmy includes powerful APIs. Add the following to lemmy.hjson
to expose or restrict APIs:
api: {
enabled: true
rate_limit: 100
}
Test the API with curl
:
curl http://example.com/api/v3/community/list
π Advanced Configurations
Customize Lemmy further by enabling federation with other instances. Add the following to the configuration file:
federation: {
enabled: true
allowed_instances: ["example.org"]
}
Restart Lemmy:
docker-compose restart lemmy
Wrapping Up
Deploying Lemmy provides a robust and customizable way to host your own link aggregator and discussion platform, with full control over data and integrations. This guide has walked you through deployment, reverse proxy setup, logging, backups, and updates. Dive into the Fediverse and start building your community with Lemmy today!