DEV Community

Akhil Naidu
Akhil Naidu

Posted on • Edited on

Installing Forem in Linux

This post is on the request of @benki

In this article, I focus less on my commentary and prefer more clarity in command execution. So if you find any words others than shell commands, take a good look at them.

One more tip while following this guide, single command lies in a single line.

This guide will be useful for anyone who wants to install forem in Linux. In a way, this is an alternative method to install Forem without Docker or Podman

Updating our system and Downloading Forem

sudo apt update
sudo apt upgrade
git clone https://github.com/forem/forem.git
cp ~/forem/.env_sample ~/forem/.env
Enter fullscreen mode Exit fullscreen mode

Ruby Installation

sudo apt install git curl autoconf bison build-essential \
    libssl-dev libyaml-dev libreadline6-dev zlib1g-dev \
    libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev
Enter fullscreen mode Exit fullscreen mode
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
exec $SHELL
Enter fullscreen mode Exit fullscreen mode
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
exec $SHELL
Enter fullscreen mode Exit fullscreen mode
rbenv install $(cat ~/forem/.ruby-version)
rbenv global $(cat ~/forem/.ruby-version)
Enter fullscreen mode Exit fullscreen mode

Install NVM and yarn

curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh -o install_nvm.sh
Enter fullscreen mode Exit fullscreen mode
bash install_nvm.sh
source ~/.profile
nvm install $(cat ~/forem/.nvmrc)
nvm use $(cat ~/forem/.nvmrc)
Enter fullscreen mode Exit fullscreen mode
npm install -g yarn
Enter fullscreen mode Exit fullscreen mode

Installing Postgre SQL

sudo apt-get install postgresql postgresql-contrib libpq-dev -y
Enter fullscreen mode Exit fullscreen mode

In the coming command, Replace the term "ubuntu" with your own username.

sudo -u postgres createuser -s ubuntu
createdb
sudo -u ubuntu psql
Enter fullscreen mode Exit fullscreen mode

Now within the psql Use \password command to create a password for the user ubuntu, in which we will create a database (later on).

You can exit psql by using the command \quit; this will help you get into the original bash/terminal of your VPS.

Let's update the DATABASE_URL and the DATABASE_URL_TEST accordingly in the .env file.

nano ~/forem/.env
Enter fullscreen mode Exit fullscreen mode
DATABASE_URL="postgresql://ubuntu:mypassword@localhost:5432/$DATABASE_NAME"
DATABASE_URL_TEST="postgresql://ubuntu:mypasswordk@localhost:5432/$DATABASE_NAME_TEST"
Enter fullscreen mode Exit fullscreen mode

Installing Imagemagick

sudo apt update && sudo apt install imagemagick
Enter fullscreen mode Exit fullscreen mode

Installing and ConfiguringRedis

sudo apt install redis-server -y
Enter fullscreen mode Exit fullscreen mode
sudo nano /etc/redis/redis.conf
Enter fullscreen mode Exit fullscreen mode

Navigate to find the variable supervised and change it's value systemd

sudo systemctl restart redis.service
Enter fullscreen mode Exit fullscreen mode

Installing Elastic search

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-oss-7.5.2-amd64.deb
Enter fullscreen mode Exit fullscreen mode
sudo dpkg -i elasticsearch-oss-7.5.2-amd64.deb
Enter fullscreen mode Exit fullscreen mode

If you are someone who is trying to experiment with this Forem in a low-end server, maybe around 1GB or 2GB ram; It is mandatory for you to do edit the memory heap. And follow these if you are one among them, or else leave.

If you are not sure about this, skip and continue with the next step, but if you are facing any error in starting Elasticsearch try referring to this.

sudo nano /etc/elasticsearch/jvm.options
Enter fullscreen mode Exit fullscreen mode
  • First, un-comment the value of Xmx and Xms.
  • Next, modify the value of -Xms and -Xmx to no more than 50% of your physical RAM
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
# Use 128m if 1GB ram and 256m if 2GB ram

-Xms128m
-Xmx128m
Enter fullscreen mode Exit fullscreen mode

Now let's start Elasticsearch

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
Enter fullscreen mode Exit fullscreen mode

Installing ImgProxy

git clone https://github.com/imgproxy/imgproxy.git
cd imgproxy
Enter fullscreen mode Exit fullscreen mode
sudo add-apt-repository ppa:dhor/myway
sudo apt-get update
sudo apt-get install libvips-dev
Enter fullscreen mode Exit fullscreen mode
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get update
sudo apt-get install golang-go
Enter fullscreen mode Exit fullscreen mode
sudo CGO_LDFLAGS_ALLOW="-s|-w" \
  go build -o /usr/local/bin/imgproxy
Enter fullscreen mode Exit fullscreen mode

Now let's configure the .env for Imgproxy

  • Generate a key/salt pair by running the following in your terminal twice. Copy those values to your .env in the next step
echo $(xxd -g 2 -l 64 -p /dev/random | tr -d '\n')
Enter fullscreen mode Exit fullscreen mode

We have one random string; but we need two of them, so let's run this command again.

echo $(xxd -g 2 -l 64 -p /dev/random | tr -d '\n')
Enter fullscreen mode Exit fullscreen mode

Now we have 2 random strings; we will one of them as key and the other as salt. This can be done by adding few lines in .env file.

nano ~/forem/.env
Enter fullscreen mode Exit fullscreen mode

Now add these three lines to it and save the file.

IMGPROXY_ENDPOINT='http://localhost:8080'
IMGPROXY_KEY='1b1c9aae804e070b0864f2547fba7ce8ff31bf7..........'
IMGPROXY_SALT='8c6d449d4fc2cada5bab538826cae709d2ade9f.........'
Enter fullscreen mode Exit fullscreen mode

Replace, the key and salt with the values you generated in few steps back. (You can interchange those values, but as a convention, I use the first one as key and the later as salt)

Also store these values in this fashion, so that we can use this command to start our Imgproxy.

IMGPROXY_KEY='your key' IMGPROXY_SALT='your salt' imgproxy
Enter fullscreen mode Exit fullscreen mode

Now we have all the required side packs for our installation

Installing and Starting Forem

If you are using a VPS, it is mandatory for you to update your APP_DOMAIN value with your VPS IP address in the .env file.

  • you can find your VPS IP address by using the command ifconfig
  • Use this command to edit your .env file: nano ~/forem/.env
sudo apt-get install libcurl4 libcurl4-openssl-dev -y
cd ~/forem
gem install bundler
yarn install
bin/setup
rails db:reset
rails data_updates:run
Enter fullscreen mode Exit fullscreen mode

Now open 3 Terminal, the three boxes below indicate 3 different terminals

  • Terminal 01
IMGPROXY_KEY='your key' IMGPROXY_SALT='your salt' imgproxy
Enter fullscreen mode Exit fullscreen mode
  • Terminal 02
./bin/webpack
bundle exec sidekiq -t 25
Enter fullscreen mode Exit fullscreen mode
  • Terminal 03
bin/rails s -p 3000 -b 0.0.0.0
Enter fullscreen mode Exit fullscreen mode

Top comments (18)

Collapse
 
sidcraftscode profile image
sid

I got this error

rails aborted!
PG::ConnectionBad: fe_sendauth: no password supplied
/home/sid/forem/app/lib/database.rb:9:in `table_exists?'
/home/sid/forem/app/models/profile.rb:53:in `refresh_attributes!'
/home/sid/forem/app/models/profile.rb:62:in `<class:Profile>'
/home/sid/forem/app/models/profile.rb:1:in `<main>'
/home/sid/forem/app/models/user.rb:60:in `block (2 levels) in <class:User>'
/home/sid/forem/app/models/user.rb:48:in `<class:User>'
/home/sid/forem/app/models/user.rb:1:in `<main>'
/home/sid/forem/vendor/cache/devise-0cd72a56f984/lib/devise.rb:316:in `get'
/home/sid/forem/vendor/cache/devise-0cd72a56f984/lib/devise/mapping.rb:83:in `to'
/home/sid/forem/vendor/cache/devise-0cd72a56f984/lib/devise/mapping.rb:78:in `modules'
/home/sid/forem/vendor/cache/devise-0cd72a56f984/lib/devise/mapping.rb:95:in `routes'
/home/sid/forem/vendor/cache/devise-0cd72a56f984/lib/devise/mapping.rb:162:in `default_used_route'
/home/sid/forem/vendor/cache/devise-0cd72a56f984/lib/devise/mapping.rb:72:in `initialize'
/home/sid/forem/vendor/cache/devise-0cd72a56f984/lib/devise.rb:346:in `new'
/home/sid/forem/vendor/cache/devise-0cd72a56f984/lib/devise.rb:346:in `add_mapping'
/home/sid/forem/vendor/cache/devise-0cd72a56f984/lib/devise/rails/routes.rb:243:in `block in devise_for'
/home/sid/forem/vendor/cache/devise-0cd72a56f984/lib/devise/rails/routes.rb:242:in `each'
/home/sid/forem/vendor/cache/devise-0cd72a56f984/lib/devise/rails/routes.rb:242:in `devise_for'
/home/sid/forem/config/routes.rb:10:in `block in <main>'
/home/sid/forem/config/routes.rb:3:in `<main>'
/home/sid/forem/config/application.rb:73:in `block in <class:Application>'
/home/sid/forem/config/environment.rb:5:in `<main>'
bin/rails:4:in `<main>'
Tasks: TOP => search:setup => environment
(See full trace by running task with --trace)

== Command ["RAILS_ENV=\"test\" bin/rails search:setup"] failed ==
Enter fullscreen mode Exit fullscreen mode
Collapse
 
akhilnaidu profile image
Akhil Naidu

Hey, the problem you are facing here is because of the non-configuration of DATABASE_URL properly.

I'm updating this article again. Until you see a clear indication at the top of the post saying Updated with 2021, consider it work under progress.

Meanwhile, you can have a quick peek at where this is going. I'm actively updating this article rather than in passive mode.

Collapse
 
ntkien2192 profile image
Nguyễn Trung Kien

Thank. Your tutorial work well. But after i add domain

APP_DOMAIN="domain.com"
APP_PROTOCOL="https://"

then my forum only can open with domain.com:3000. Any way i can remove port 3000 and change http to https

Collapse
 
akhilnaidu profile image
Akhil Naidu

A much better option would be, for development.

Use nginx as a reverse proxy for port 3000.

Collapse
 
ntkien2192 profile image
Nguyễn Trung Kien

Thanks a lot. Now i get a new one when i try to login with social acc call: ActionController:: InvalidAuthenticityToken

Collapse
 
ntkien2192 profile image
Nguyễn Trung Kien

i Follow this one, My Forem open success but i get ActionController:: InvalidAuthenticityToken everytime i try to login.

Collapse
 
ntkien2192 profile image
Nguyễn Trung Kien

Can i fix it with some step?

Collapse
 
akhilnaidu profile image
Akhil Naidu

Hey, if you are interested in hosting Forem in production. This is not the preferred way.

I'm actually working on a project to help Forem selfhosters. If you are interested, I can provide you access to the pre-release version.

Thread Thread
 
ntkien2192 profile image
Nguyễn Trung Kien

thank a lot, please add me with email ntkien2192@gmail.com

Thread Thread
 
akhilnaidu profile image
Akhil Naidu

I will create an account for you and will let you know, once it is done. We are few days behind to release v0.3

Thread Thread
 
ntkien2192 profile image
Nguyễn Trung Kien

thanks

Collapse
 
bientran profile image
Fire Keeper

How do I run forem for the production site?
Could you describe a little bit about production configuration?
Thanks!

Collapse
 
akhilnaidu profile image
Akhil Naidu
Collapse
 
akhilnaidu profile image
Akhil Naidu

Updated :)

Collapse
 
coderlifeisawesome profile image
lifeascoder

I am not able to login using my Github account or neither sign up. It is showing an error and I am stuck with it. What to do?

Collapse
 
ngtrian profile image
Tri Ân

I'm not sure how and how about Now open 3 Terminal, the three boxes below indicate 3 different terminals paragraph

Collapse
 
akhilnaidu profile image
Akhil Naidu

Hello, yes it means that.

But if you are following this post, there is no need for you to configure anything related to elastic search. Forem removed the need of it.

You can follow my posts over here for updated content: forem.dev/akhil/series

Collapse
 
luuvuong profile image
luuvuong • Edited

/start web container not start by problem connect postgresql
Image description