9.2 KiB
Install Production Environment
Hope this article can help you about install production environment.
Introduction
This article is written based on the Debian Bookworm. Other systems can refer to this article for deployment. However, it is recommended that new users use the same system or Docker environment as ours to avoid wasting time on environment configuration issues.
The versions of Node.js, Rust, PostgreSQL, DragonflyDB that come with Debian Bookworm are low or not have, the latest official versions of these components are used to install them. Other components are installed using the apt package manager that comes with the system.
Allow sudo
command
su -
apt install -y -V sudo
# user is your username
usermod -aG sudo user
reboot
Install Base Requirements
sudo apt update
sudo apt install -y -V wget curl git ca-certificates
Install Node.js
The latest version at the time of writing is v21.6.2. Please replace it with the latest Node.js version number during installation. Details can be found in nodejs.org .
- Download and extract.
VERSION=v21.6.2
DISTRO=linux-x64
sudo mkdir -p /usr/local/lib/nodejs
wget https://nodejs.org/dist/v21.6.2/node-$VERSION-$DISTRO.tar.xz
sudo tar -xJvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs
- Open your
.profile
and/root/.profile
files.
nano ~/.profile
sudo nano /root/.profile
- Add below content at below of this two file to set the environment variable.
# Nodejs
VERSION=v21.6.2
DISTRO=linux-x64
export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH
- Refresh
PATH
and test.
. ~/.profile
node -v
# Switching to root
sudo -i
. ~/.profile
node -v
exit
Install Rust
- Running this script and choose "Proceed with installation" option.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
. ~/.profile
cargo -V
Install PostgreSQL with PGroonga extension
wget https://apache.jfrog.io/artifactory/arrow/$(lsb_release --id --short | tr 'A-Z' 'a-z')/apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb
sudo apt install -y -V ./apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb
wget https://packages.groonga.org/debian/groonga-apt-source-latest-$(lsb_release --codename --short).deb
sudo apt install -y -V ./groonga-apt-source-latest-$(lsb_release --codename --short).deb
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release --codename --short)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt update
sudo apt install -y -V postgresql-16-pgdg-pgroonga
Configuration PostgreSQL
- Execute this to running
psql
aspostgres
user.
sudo -u postgres psql
- Create Firefish database, user and PGroonga extension. Please change the password.
CREATE DATABASE firefish WITH ENCODING = 'UTF8';
\connect firefish
CREATE EXTENSION IF NOT EXISTS pgroonga;
CREATE USER firefish WITH PASSWORD 'password';
ALTER USER firefish WITH SUPERUSER;
GRANT ALL ON DATABASE firefish TO firefish;
- Run
exit
to return.
Install DragonflyDB (Cache)
wget https://dragonflydb.gateway.scarf.sh/latest/dragonfly_amd64.deb
sudo dpkg -i dragonfly_amd64.deb
Configuration DragonflyDB
If you experience a lot of traffic, it's a good idea to set up another Redis-compatible caching server. If you don't set one one up, it'll fall back to the mandatory Redis server. DragonflyDB is the recommended option due to its unrivaled performance and ease of use.
- Open your
dragonfly.conf
files.
sudo nano /etc/dragonfly/dragonfly.conf
- Add content at below of this file to set the different port variable because default port is 6379.
--port=6380
- Run
sudo systemctl restart dragonfly
to restart it.
Install Caddy, Redis, Python 3 and build-essential
If you already have experience using nginx, you can consider replacing caddy with nginx here.
sudo apt update
sudo apt install -y -V caddy redis python3 build-essential
Configuration Caddy
If you replaced nginx in the previous step, please refer to the "Other reverse proxy server" chapter in the document for configuration.
- Run this to modify caddy configuration.
sudo nano /etc/caddy/Caddyfile
- Add this below, should change
example.tld
to your domain.
example.tld {
reverse_proxy http://127.0.0.1:3000
}
- Running
sudo systemctl restart caddy
to apply.
Download and configuration Firefish
- Download Firefish and Copy example configuration file.
# cd /path/to/your/firefish
git clone https://firefish.dev/firefish/firefish.git
cd firefish/
git checkout main
cp .config/example.yml .config/default.yml
Note
By default, you're on the develop branch. Run
git checkout main
to switch to the Main branch.
- Open your
default.yml
files and make changes likeURL
,db
andreservedUsernames
.
nano .config/default.yml
Install Firefish
run these steps to update Firefish in the future!
- Let corepack enable.
# Switching to root
sudo -i
# cd /path/to/your/firefish
cd /home/user/firefish
npm i -g pm2
corepack enable
exit
- Install dependency.
corepack prepare pnpm@latest --activate
pnpm install --frozen-lockfile --prod false
pm2 install pm2-logrotate
Note
pm2-logrotate
ensures that log files don't infinitely gather size, as Firefish produces a lot of logs.
- Build and migrate
pnpm install --prod false
NODE_ENV=production pnpm run build && pnpm run migrate
- Start Firefish
pm2 start "NODE_ENV=production pnpm run start" --name Firefish
pm2 logs Firefish
- Wait until the following message shows up.
1|Firefish | DONE * [core boot] All workers started
1|Firefish | DONE * [core boot] Now listening on port 3000 on https://your_firefish_url.example.com (default value: https://localhost:3000)
-
A fresh Firefish environment is created on the URL you have set!
-
By the way, Please use content at below to generate vapid keys to enable Push-Notifications.
# Switching to root
sudo -i
npm install -g web-push
web-push generate-vapid-keys
exit
Customize
- To add custom CSS for all users, edit
./custom/assets/instance.css
. - To add static assets (such as images for the splash screen), place them in the
./custom/assets/
directory. They'll then be available onhttps://yourserver.tld/static-assets/filename.ext
. - To add custom locales, place them in the
./custom/locales/
directory. If you name your custom locale the same as an existing locale, it will overwrite it. If you give it a unique name, it will be added to the list. Also make sure that the first part of the filename matches the locale you're basing it on. (Example:en-FOO.yml
) - To add custom error images, place them in the
./custom/assets/badges
directory, replacing the files already there. - To add custom sounds, place only mp3 files in the
./custom/assets/sounds
directory. - To update custom assets without rebuilding, just run
pnpm run gulp
. - To block ChatGPT, CommonCrawl, or other crawlers from indexing your instance, uncomment the respective rules in
./custom/robots.txt
.
Other reverse proxy server
Nginx
- Run
sudo cp ./firefish.nginx.conf /etc/nginx/sites-available/ && cd /etc/nginx/sites-available/
. - Edit
firefish.nginx.conf
to reflect your server properly. - Run
sudo ln -s ./firefish.nginx.conf ../sites-enabled/firefish.nginx.conf
. - Run
sudo nginx -t
to validate that the config is valid, then restart the NGINX service.
Tips & Tricks
- When editing the config file, please don't fill out the settings at the bottom. They're designed only for managed hosting, not self hosting. Those settings are much better off being set in Firefish's control panel.
- Port 3000 (used in the default config) might be already used on your server for something else. To find an open port for Firefish, run
for p in {3000..4000}; do ss -tlnH | tr -s ' ' | cut -d" " -sf4 | grep -q "${p}$" || echo "${p}"; done | head -n 1
. Replace 3000 with the minimum port and 4000 with the maximum port if you need it. - I'd recommend you use a S3 Bucket/CDN for Object Storage, especially if you use Docker.
- When using object storage, setting a proper
Access-Control-Allow-Origin
response header is highly recommended. - I'd strongly recommend against using CloudFlare, but if you do, make sure to turn code minification off.
- For push notifications, run
npx web-push generate-vapid-keys
, then put the public and private keys into Control Panel > General > ServiceWorker. - For translations, make a DeepL account and generate an API key, then put it into Control Panel > General > DeepL Translation.
- To add another admin account:
- Go to the user's page > 3 Dots > About > Moderation > turn on "Moderator"
- Go back to Overview > click the clipboard icon next to the ID
- Run
psql -d firefish
(or whatever the database name is) - Run
UPDATE "user" SET "isAdmin" = true WHERE id='999999';
(replace999999
with the copied ID) - Restart your Firefish server