...

How to deploy forem on rocky linux vpsThis article provides a guide detailing how to deploy Forem on Rocky Linux VPS.

What is Forem?

Forem is a robust, open-source platform for building communities like DEV.to. Deploying it on Rocky Linux involves setting up dependencies like PostgreSQL, Redis, Elasticsearch, and configuring Rails with a production-ready environment.

βœ… Tested on Rocky Linux 8/9 (x86_64)
πŸ’‘ Recommended VPS Specs: 2+ vCPU, 4GB+ RAM, 40GB+ disk, Rocky Linux 8 or Rocky Linux 9

Launch 100% ssd rocky linux vps from $2. 49/mo!

How to Deploy Forem on Rocky Linux VPS

To deploy Forem on Rocky Linux VPS, follow the steps below:

  1. Update and Prepare System

    Login as root via SSH and run the following commands:

    sudo dnf update -y
    sudo dnf install -y epel-release nano
    sudo dnf install -y gcc make zlib-devel openssl-devel libyaml-devel readline-devel python36 python3-pip python3-setuptools
    sudo dnf groupinstall -y "Development Tools"
    
  2. Install Ruby

    git clone https://github.com/rbenv/rbenv.git ~/.rbenv
    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    echo 'eval "$(rbenv init -)"' >> ~/.bashrc
    source ~/.bashrc
    git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
    rbenv install 3.2.2
    rbenv global 3.2.2
    gem install bundler
    gem install rails
    
  3. Install Required Dependencies

    Install core libraries and tools:

    sudo dnf install -y curl git wget nodejs gcc-c++ patch \
      readline readline-devel zlib zlib-devel \
      libyaml-devel libffi-devel openssl-devel make \
      bzip2 autoconf automake libtool bison sqlite-devel \
      ImageMagick ImageMagick-devel libxslt libxslt-devel libxml2 libxml2-devel
    
  4. Install Docker and Docker Compose

    # Install Docker
    sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    sudo dnf install -y docker-ce docker-ce-cli containerd.io
    
    # Enable and start Docker
    sudo systemctl enable --now docker
    
    # Add user to docker group
    sudo usermod -aG docker $USER
    

    πŸšͺ Log out and back in for group change to take effect.

    Install Docker Compose:

    sudo curl -L "https://github.com/docker/compose/releases/download/v2.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose
    
  5. Clone the Forem Repository

    git clone https://github.com/forem/selfhost.git
    cd selfhost
    

    Switch to stable branch:

    git checkout main
    
  6. Configure Docker Environment

    Create a .env file:

    ./setup
    

    Edit the .env file to suit your setup:

    nano .env
    

    Update important variables:

    RAILS_ENV=production
    APP_DOMAIN=yourdomain.com
    SECRET_KEY_BASE=generate_this_soon
    
  7. Generate SECRET_KEY_BASE

    docker run --rm forem/rails bin/rake secret
    

    Copy the output and paste it into .env as SECRET_KEY_BASE.

  8. Launch Forem Using Docker Compose

    docker-compose up -d
    

    This will set up:

    • Rails app
    • PostgreSQL
    • Redis
    • Sidekiq
    • Elasticsearch
    • Fastly stub

    πŸ“ Check logs with:
    docker-compose logs -f

  9. Setup Database and Assets

    Run the following to create and seed the database:

    docker-compose run --rm web bin/rails db:setup
    docker-compose run --rm web bin/rails assets:precompile
    
  10. Configure NGINX Reverse Proxy

    Install NGINX:

    sudo dnf install -y nginx
    sudo systemctl enable --now nginx
    

    Configure SSL (optional but recommended with Certbot):

    sudo dnf install -y certbot python3-certbot-nginx
    sudo certbot --nginx -d yourdomain.com
    

    Configure /etc/nginx/conf.d/forem.conf:

    server {
        listen 80;
        server_name yourdomain.com;
    
        location / {
            proxy_pass http://localhost:3000;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_http_version 1.1;
        }
    }
    

    Reload NGINX:

    sudo nginx -t && sudo systemctl reload nginx
    
  11. Secure the Server

    Enable FirewallD

    sudo dnf install -y firewalld
    sudo systemctl enable --now firewalld
    sudo firewall-cmd --permanent --add-service=http
    sudo firewall-cmd --permanent --add-service=https
    sudo firewall-cmd --reload
    
  12. Access Your Forem

    Visit: http://yourdomain.com
    You should see the Forem homepage. The first user you register becomes the admin.

Troubleshooting Tips

Symptom Possible Fix
App not loading Check docker-compose logs web
DB connection error Ensure db service is running and accessible
Missing assets Run bin/rails assets:precompile
Certbot fails Ensure DNS is pointed correctly and port 80/443 open

Launch 100% ssd rocky linux vps from $2. 49/mo!

βœ… Conclusion

You now know how to deploy Forem on Rocky Linux VPS using Docker and NGINX. You now have a powerful open-source community platform ready to go!

Avatar of editorial staff

Editorial Staff

Rad Web Hosting is a leading provider of web hosting, Cloud VPS, and Dedicated Servers in Dallas, TX.
lg