How to Install Lemmy on Clear Linux Latest
Lemmy is a link aggregation and discussion platform that is similar to Reddit. It is a self-hosted alternative that allows users to create their own communities without fear of being censored or controlled by a larger corporation. In this tutorial, we will walk through the steps to install Lemmy on Clear Linux Latest using the command line.
Prerequisites
Before we begin, make sure that you have:
- A Clear Linux Latest instance with sudo access
- A domain name or subdomain that points to your server's IP address
- A valid SSL certificate
- A registered Google OAuth client ID and secret (required for user authentication)
Step 1: Install Dependencies
Lemmy requires the following dependencies:
- PostgreSQL
- Redis
- Rust
- Nginx
- OpenSSL
Clear Linux makes this process easy with the swupd command. To install all necessary dependencies, enter the following command:
sudo swupd bundle-add devpkg-rust devpkg-redis devpkg-postgresql devpkg-openssl nginx-basic
Step 2: Build and Install Lemmy
Lemmy is open-source software, meaning that you can download the installation files from the existing repositories.
Clone the repository using the following command:
git clone https://github.com/LemmyNet/lemmy.gitBuild the project to create the Lemmy binary. To do so, enter the following command:
cargo build --releaseInstall the binary by entering the following command:
sudo install -Dm755 ./target/release/lemmy /usr/local/bin/lemmy
Step 3: Configure PostgreSQL
Create a new user by entering the following command:
sudo -u postgres createuser --pwprompt lemmyuserWhen prompted, create a password for the new user.
Create a new database by entering the following command:
sudo -u postgres createdb lemmydb -O lemmyuserSet the password for the newly created database user. Open the PostgreSQL shell:
sudo -u postgres psqlThen enter the following commands to set the password:
ALTER USER lemmyuser WITH PASSWORD 'your_password';Exit out of the PostgreSQL shell by typing:
\q
Step 4: Configure Lemmy
Lemmy uses a configuration file named Rocket.toml. You can create the file like this:
sudo nano /etc/lemmy/Rocket.toml
Configure the file with the following code snippet. Replace your_domain.tld with your actual domain name or subdomain.
[global]
secret_key = "your_secret_generated_by_lemmy"
db_url = "postgresql://lemmyuser:your_password@localhost/lemmydb"
allowed_origins = ["https://your_domain.tld"]
google_client_id = "your_google_client_id.apps.googleusercontent.com"
google_client_secret = "your_google_client_secret"
[development]
log = "debug"
[testing]
log = "warn"
[release]
log = "info"
Step 5: Configure Nginx
Lemmy is a web application, and it needs a web server to function properly. In this tutorial, we will be using Nginx.
Create a configuration file for your domain or subdomain. Replace
your_domain.tldwith your actual domain name or subdomain.sudo nano /etc/nginx/conf.d/your_domain.tld.confConfigure the file with the following code snippet. Replace
your_domain.tldwith your actual domain name or subdomain.server { listen 80; listen [::]:80; server_name your_domain.tld; return 301 https://$host$request_uri; } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name your_domain.tld; ssl_certificate /path/to/your/ssl/certificate; ssl_certificate_key /path/to/your/ssl/private/key; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://127.0.0.1:8000; } }Save and close the file.
Test that your Nginx configuration file is valid:
sudo nginx -tReload the Nginx service for changes to take effect:
sudo systemctl reload nginx
Step 6: Run Lemmy
Run Lemmy in the background with the following command:
nohup /usr/local/bin/lemmy &This command launches Lemmy in the background and creates a log file in your home directory called nohup.out.
Verify that Lemmy is running:
sudo lsof -i :8000Output should include something like this:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME lemmy 23431 clearuser 22u IPv4 583126 0t0 TCP *:8000 (LISTEN)Visit your domain or subdomain in a web browser. If everything is set up correctly, Lemmy should be running!
If you experience issues, review and verify that all previous steps have been completed successfully.
Congratulations, you have installed Lemmy on Clear Linux Latest!