forem.dev Community

loading...
Cover image for Self-hosting Forem on Digital Ocean Servers.

Self-hosting Forem on Digital Ocean Servers.

akhil profile image Akhil Naidu Updated on ・4 min read

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

Discussion (13)

pic
Editor guide
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 Author

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
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 Author

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
akhil profile image
Akhil Naidu Author

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

Collapse
ioscasey profile image
Casey 💎

Great stuff!

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 Author

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
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 Author

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

I can guide you though.