Flarum is a forum software that is easy to use, customizable and lightweight. In this tutorial, we will be installing Flarum on NixOS Latest.
Before you start installing Flarum, make sure you have the following prerequisites:
Open your terminal and run the following command to install Flarum using Nix:
sudo nix-env -iA nixos.flarum
This command will download and install Flarum on your system.
Create a new file /etc/systemd/system/flarum.service
and add the following content:
[Unit]
Description=Flarum Forum
After=network.target
[Service]
Type=simple
WorkingDirectory=/var/flarum
ExecStart=/run/current-system/sw/bin/php flarum flarum:start
User=flarum
Group=www
[Install]
WantedBy=multi-user.target
Save the file and close it.
Create a new user and group for Flarum using the following command:
sudo useradd -m -U -r -d /var/flarum -s /bin/false flarum
The above command creates a new user named flarum
with home directory /var/flarum
and sets the shell to /bin/false
.
Change the ownership of /var/flarum
directory to flarum
and www
group:
sudo chown -R flarum:www /var/flarum
Install Nginx using the following command:
sudo nix-env -iA nixos.nginx
Create a new Nginx configuration file for Flarum by running the following command:
sudo nano /etc/nginx/sites-available/flarum.conf
Add the following content to the file:
server {
listen 80;
server_name forum.example.com; # Replace with your own domain or IP
root /var/flarum/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /api {
try_files $uri $uri/ /api.php?$query_string;
}
}
Save the file and close it.
Create a symbolic link from sites-available/flarum.conf
to sites-enabled/flarum.conf
by running the following command:
sudo ln -s /etc/nginx/sites-available/flarum.conf /etc/nginx/sites-enabled/flarum.conf
Reload Nginx to apply the changes:
sudo systemctl restart nginx
Install the required PHP extension for Flarum using the following command:
sudo nix-env -iA nixos.php74Extensions.php74-pdo_sqlite
Login to the system as the user flarum
and run the following command to install Flarum:
php flarum install
This command will start the installation wizard for Flarum. Follow the on-screen instructions to complete the installation.
Start the Flarum service using the following command:
sudo systemctl start flarum
Enable the Flarum service to start at boot:
sudo systemctl enable flarum
Congratulations! You have successfully installed Flarum on NixOS Latest. You can now access your Flarum installation by visiting your domain name or IP address in your web browser.
If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!
Alternatively, for the best virtual desktop, try Shells!