Forem Creators and Builders 🌱

Cover image for Development: Self-hosting Forem on Digital Ocean Servers.
Akhil Naidu
Akhil Naidu

Posted on • Updated on

Development: Self-hosting Forem on Digital Ocean Servers.

> Update: There is no requirement of Elasticsearch in the new Forem
Enter fullscreen mode Exit fullscreen mode

In this article, I focus less on my commentary and prefer more clarity in command execution. So if you find any words other 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

Here is one of the living and breathing Forem Instance through VPS. Working Forem in Digital Ocean

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-dev-server
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

This is an actively developing article, so you will find more commands than the usual commentary

Also, this article is not covering any sort of domain integrations; if you have any trouble in configuring Nginx and need some assistance, please let me know. I can help you in the comment section or update the article accordingly

Oldest comments (22)

Collapse
 
akhil profile image
Akhil Naidu

If you have any doubts, let me know in the comment section.

Collapse
 
coffeecraftcode profile image
Christina Gorton

Looking through this now but also just wanted to say thank you for documenting this! I know it will be helpful for a lot of people and I really appreciate you taking the time to put in to words all the things you have been learning while working to set up Forem for yourself.

Collapse
 
akhil profile image
Akhil Naidu

I hope one day, I will be able to write detailed documentation of Forem from development -> production to the majority of its users (personal -> enterprise)

I'm not good with web development, especially with ruby on rails. So by documenting, I can be a part of this community :)

Collapse
 
coffeecraftcode profile image
Christina Gorton

Definitely. Documentation is vital and super helpful! It is definitely a great contribution to this community.

Collapse
 
jdoss profile image
Joe Doss

Hey @akhil thanks for taking the time to write all of this up and your hard work on getting Forem installed on your DO account. We are actually in the process of finishing up a Forem Selfhost repo that will streamline a lot of this process for users on Digital Ocean, AWS and Google Compute. Be sure to keep an eye out on forem.dev for news about that.

Collapse
 
lee profile image
Lee

Can’t wait to see this @jdoss πŸŒžπŸ˜€

Collapse
 
akhil profile image
Akhil Naidu

Yes, I'm with you.

Collapse
 
alvarolab profile image
Álvaro Hurtado Mochón

Really want to see this!
I have been trying for a while, so far painfully and unsuccessful!

Collapse
 
yanoe profile image
Yanoe?

@jdoss Hi, any update its 2023, I want to host Forem in digital ocean

Collapse
 
ioscasey profile image
Casey πŸ’Ž

Great stuff!

Collapse
 
flarumtr_44 profile image
flarumtr

I am really curious about the contents of the nginx.conf file. I will be grateful if you share the nginx.conf file of the DO instance.

Collapse
 
akhil profile image
Akhil Naidu

There are lot of other nginx configurations within my file, so I cant directly share it.

I can guide you though.

Collapse
 
wassim_elbhm profile image
WASSIM EL BOUHAMIDI

Hey! how I can contact you, bro? I have a lot of question.

Collapse
 
akhil profile image
Akhil Naidu

My Facebook

If you are not a fb user, you can mail me: admin@leewardslope.com

If you are not good with emails, suggest me your prefered social media platforms.

Collapse
 
ce7in profile image
Muhammed Cetin

I've sent a friendship request on Facebook and LinkedIn. When you have a free time, I want to discuss about installation of Forem on Heroku. I couldn't install it, heroku throw some errors.

Collapse
 
ngtrian profile image
Tri Γ‚n

Is it possible to run forem production with apache instead of nginx

Collapse
 
akhil profile image
Akhil Naidu

Think of it like this. Forem service will be open on port 3000. DNS providers don't accept random ports(most of them only prefer 80 and 443, which is plain IP).

So, any service that port forward the service port 3000 to 80 is fine.

Collapse
 
ngtrian profile image
Tri Γ‚n

I have set up a ProxyPass on 127.0.0.1:3000/, and the website runs successfully, but when I close the terminal window, the website also stops.
Is there a way forem to still run even when I close the terminal window

Thread Thread
 
akhil profile image
Akhil Naidu

Use tmux

Collapse
 
ngtrian profile image
Tri Γ‚n • Edited

Overmind has handled tmux for you by running as a daemon, here's the command line to launch the application instead of using bin/startup:
overmind s -D -f Procfile.dev

Collapse
 
coffeecraftcode profile image
Christina Gorton

Hey @navjotbabrah The self-host repo is github.com/forem/selfhost.git.

Akhil has done a wonderful job setting up their Forem and creating some guides on how they did it.

If you are looking to get support from the Forem team in the future please follow the steps in the self-host repo github.com/forem/selfhost or in these official guides.
forem.dev/foremteam/self-host-quic...

You can also feel free to follow Akhil's guides as well. We at Forem just can't offer support for that set up if you run in to problems in the future. However the community here may be able to answer your questions.
Thanks!

 
coffeecraftcode profile image
Christina Gorton

@navjotbabrah Thanks for adding more context here. If you would like to see what Forem looks like locally you can use the forem/forem repo. Forem is the software that powers all of the forems and what the self-host repo uses as well. If you want to deploy your own Forem we suggest using the forem/selfhost repo :) Let me know if you have any questions.