Lemmy is an open-source, self-hosted, federated, Reddit-like platform for discussions, analysis, and sharing links. It is a great alternative to centralized platforms like Reddit and allows users to create their own communities, and manage their discussions.
In this tutorial, we will show you how to install Lemmy on Ubuntu Server Latest.
Before starting, make sure you have met the following prerequisites:
A server running Ubuntu Server Latest.
A non-root user with sudo privileges.
A domain name pointing to your server IP address. In this tutorial, we will use lemmy.example.com
as our domain name.
Before installing any packages, it is recommended to update your server to the latest version. To do this, log in to your server as a non-root user with sudo privileges and run the following command:
sudo apt update && sudo apt upgrade
Lemmy requires some dependencies to be installed on the server. You can install them using the following command:
sudo apt install -y cargo git nginx certbot python3-certbot-nginx postgresql postgresql-contrib libssl-dev pkg-config build-essential
cargo
is the Rust programming language package manager.
git
is the version control system for the source code.
nginx
is the web server that will handle the HTTP requests.
certbot
is the tool used to obtain SSL certificates from Let's Encrypt.
python3-certbot-nginx
is the Certbot plugin that automates the SSL certificate installation on the Nginx server.
postgresql
is the open-source relational database management system.
postgresql-contrib
is the collection of additional tools and extensions for PostgreSQL.
libssl-dev
and pkg-config
are necessary for compiling the source code, while build-essential
is required for installing the dependencies.
Next, you need to clone the Lemmy repository from GitHub. To do this, run the following command:
git clone https://github.com/LemmyNet/lemmy.git
This will download the latest version of the Lemmy source code to your server.
Now, you can build the Lemmy Rust binaries using the cargo package manager.
First, navigate to the lemmy
directory:
cd lemmy
Then, run the following command:
RUSTFLAGS="-C target-cpu=native" cargo build --release
This will take some time, as it will compile all the Rust dependencies and the Lemmy source code. Once completed, the binaries will be stored in the target/release
directory.
Now, you need to configure Nginx as a reverse proxy server for Lemmy. Create a new Nginx virtual host configuration file:
sudo nano /etc/nginx/sites-available/lemmy.example.com
Paste the following Nginx configuration:
server {
listen 80;
listen [::]:80;
server_name lemmy.example.com;
# Redirect HTTP requests to HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name lemmy.example.com;
ssl_certificate /etc/letsencrypt/live/lemmy.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/lemmy.example.com/privkey.pem;
location / {
# Proxy settings
proxy_pass http://localhost: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;
# Websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Make sure you replace lemmy.example.com
with your domain name.
Save and close the file.
Now, create a symbolic link to enable the virtual host configuration:
sudo ln -s /etc/nginx/sites-available/lemmy.example.com /etc/nginx/sites-enabled/
Test the Nginx configuration and restart the server:
sudo nginx -t && sudo systemctl restart nginx.service
Lemmy requires a PostgreSQL database to store the data. Create a new database and user for Lemmy using the following commands:
sudo -u postgres createuser -P lemmy
sudo -u postgres createdb -O lemmy lemmy
You will be prompted to enter a password for the user.
In this step, you need to configure the Lemmy server by creating a .env
file.
Navigate to the lemmy
directory:
cd /home/your_username/lemmy
Create a new .env
file and paste the following configuration:
ROCKET_ADDRESS=localhost
DATABASE_URL=postgres://lemmy:lemmy_password@localhost/lemmy
FRONT_END_ADDRESS=https://lemmy.example.com
SERVER_ADMIN_EMAIL=your_email_address
SITE_NAME=Lemmy
SITE_HOST=https://lemmy.example.com
SITE_PORT=80
SECRETKEY=your_secret_key
REQUIRE_ACCOUNT_CONFIRMATION=false
ALLOW_ANONYMOUS_POSTING=true
SMTP_TRANSPORT=smtp
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=465
SMTP_USERNAME=your_gmail_address
SMTP_PASSWORD=your_gmail_password
DEFAULT_FROM_EMAIL=your_gmail_address
GLOBAL_OAUTH_CLIENT_ID=your_oauth_client_id
GLOBAL_OAUTH_CLIENT_SECRET=your_oauth_client_secret
GLOBAL_OAUTH_REDIRECT_URI=https://lemmy.example.com/api/v3/auth/callback
Make sure you replace the values with your own values:
DATABASE_URL
: the database URL of the PostgreSQL server.
FRONT_END_ADDRESS
: the address of your Lemmy domain.
SERVER_ADMIN_EMAIL
: the email address of the site administrator.
SITE_HOST
: the URL of your Lemmy site.
SECRETKEY
: a unique key used for encrypting the data.
SMTP_USERNAME
, SMTP_PASSWORD
, and DEFAULT_FROM_EMAIL
: the Gmail account credentials for sending emails.
GLOBAL_OAUTH_CLIENT_ID
, GLOBAL_OAUTH_CLIENT_SECRET
, and GLOBAL_OAUTH_REDIRECT_URI
: the OAuth credentials for authenticating users with third-party services.
Save and close the file.
Now, you can start the Lemmy server using the following command:
sudo RUST_BACKTRACE=1 nohup ./target/release/lemmy &> /dev/null &
This will start the Lemmy server in the background with logging disabled. You can now access your Lemmy site by visiting https://lemmy.example.com
.
To enable HTTPS on your Lemmy site, you need to obtain an SSL certificate from Let's Encrypt using Certbot.
To obtain a certificate, run the following command:
sudo certbot --nginx -d lemmy.example.com
This will guide you through the process of obtaining a certificate and configuring Nginx to use it.
In this tutorial, you have learned how to install and configure Lemmy on Ubuntu Server Latest. You can now create communities and manage your discussions on your self-hosted platform.
If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!
Alternatively, for the best virtual desktop, try Shells!