There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

Self-hosting Lemmy on Hetzner

This weekend I installed my own Lemmy instance, so I want to share the instructions to help others, who want to do the same.

I used the Ansible script and it was pretty easy. First I wanted to use my existing PosgreSQL server, what I already use for my Akkoma server. It didn’t really work out that well, the migrations failed and I couldn’t figure out what didn’t work. Eventually I just went back using PostgreSQL on Docker. If you don’t start modifying the script, and just use the dockerized PostgreSQL, you will have no problems with the installation.

What you need first is a cheap (or expensive, if you decide to invite million friends to your instance) VPS: I use Hetzner Cloud, which has been working for me super well for many years and I’m very happy with the service. I got the second cheapest AMD instance, with two cores and two gigabytes of RAM. Before buying the instance, you need to upload an SSH key to Hetzner. If you don’t have one, creating is easy from the command line: ssh-keygen -t ecdsa. What you need to give to Hetzner is your public key; the one with the .pub extension in your $HOME/.ssh directory. Do not give the private key to anyone. Go with Ubuntu, might work the best with the Ansible script.

You can now SSH to the instance: ssh root@<ip-address from the Hetzner control panel>.

Next what you need is a domain name for the server. Lemmy wants an A record, and being a good internet citizen, you also get an AAAA record for the IPv6 users. I use Cloudflare for my DNS records. It’s very easy to set them from their control panel. Do not set the proxy on just yet, we’ll come back to that later. You can get the IP addresses from the Hetzner panel. The IPv4 you just copy, for the IPv6 you have to replace the ::/64 with ::1.

Now you should be able to ssh to your instance with the new domain name. It’s time to follow the Ansible instructions for Lemmy, just run the script and see it’s done correctly with no errors. When you can login to your Lemmy instance as an admin, go back to Cloudflare and turn on proxying to your A and AAAA records to hide your server IP and prevent DDOS attacks.

The first time federation is a bit slow in the beginning. Go to search in your instance, and search for !lemmy. It takes a while for the result to arrive. You can SSH to your instance, and look for the logs of your Lemmy image:

<pre style="background-color:#ffffff;">
<span style="color:#323232;">root@lemmy:~# docker ps
</span><span style="color:#323232;">CONTAINER ID   IMAGE                        COMMAND                  CREATED        STATUS        PORTS                                NAMES
</span><span style="color:#323232;">9e940b84cc45   dessalines/lemmy-ui:0.17.3   </span><span style="color:#183691;">"docker-entrypoint.s…"</span><span style="color:#323232;">   22 hours ago   Up 22 hours   127.0.0.1:6719-</span><span style="font-weight:bold;color:#a71d5d;">></span><span style="color:#0086b3;">1234</span><span style="color:#323232;">/tcp             lemmynaukio_lemmy-ui_1
</span><span style="color:#323232;">6442d9d93554   dessalines/lemmy:0.17.3      </span><span style="color:#183691;">"/app/lemmy"</span><span style="color:#323232;">             22 hours ago   Up 22 hours   127.0.0.1:20926-</span><span style="font-weight:bold;color:#a71d5d;">></span><span style="color:#0086b3;">8536</span><span style="color:#323232;">/tcp            lemmynaukio_lemmy_1
</span><span style="color:#323232;">36a030f7bf27   asonix/pictrs:0.3.1          </span><span style="color:#183691;">"/sbin/tini -- /usr/…"</span><span style="color:#323232;">   22 hours ago   Up 22 hours   6669/tcp, 127.0.0.1:8934-</span><span style="font-weight:bold;color:#a71d5d;">></span><span style="color:#0086b3;">8080</span><span style="color:#323232;">/tcp   lemmynaukio_pictrs_1
</span><span style="color:#323232;">979be89076b2   postgres:15-alpine           </span><span style="color:#183691;">"docker-entrypoint.s…"</span><span style="color:#323232;">   22 hours ago   Up 22 hours   5432/tcp                             lemmynaukio_postgres_1
</span><span style="color:#323232;">774112d48c87   mwader/postfix-relay         </span><span style="color:#183691;">"/root/run"</span><span style="color:#323232;">              23 hours ago   Up 23 hours   25/tcp                               lemmynaukio_postfix_1
</span>
<pre style="background-color:#ffffff;">
<span style="font-weight:bold;color:#a71d5d;">></span><span style="color:#323232;"> docker logs -f 6442d9d93554
</span>

This should start showing you the federated posts in real time. Eventually your search will show up, you can click the community open and subscribe to it. Do the same for other communities what you want to follow, federate other instances and eventually you are part of the federation. It gets faster and easier for the other users, but the beginning is a bit slow.

Congratulations, you’re now a Lemmy admin and part of the bigger federation.

Malin ,

I used docker-compose version and had to work around a couple of bugs like needing to redundantly install Nginx and Let's Encrypt for it to work properly with SSL and also having to add the lemmy container to the internet facing network due to the DNS not working on it and subsequently loosing federation capability. Overall a bit of a struggle, but this is common with FOSS.

MentallyExhausted ,

Is there a way to tell it to use an existing nginx instance? I run nginx proxy manager for all my stuff and can’t forward 80/443 twice.

Malin ,

Well if you are using docker-compose you could probably get rid of the nginx container and only deploy the other four: lemmy, lemmy-ui, pictrs, postgres. You would then use the nginx.conf stuff you have in place for the docker container of nginx to proxy to lemmy-ui and lemmy on ports 1234 and 8536. Or if you plan to keep using the docker container for nginx then you can change the listening port in the nginx.conf of the container:

listen 80;

to something different like

listen 1080;

Also in the docker-compose.yml you would update the nginx ports to 1080:1080.

Hope this answers your question.

AnonStoleMyPants ,

Thanks for the post! Been thinking of spinning my own instance as well because my Hetzner server doesn’t get used that much. Though then I would have to actually make sure it stays up and that I won’t just dip out one day lol.

pimeys OP ,
@pimeys@lemmy.nauk.io avatar

If you have the talent to run a server somewhere, do it for your friends and get people to the Lemmy ecosystem.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • [email protected]
  • lifeLocal
  • goranko
  • All magazines