How to Install Flarum on NixOS Latest
Flarum is a forum software that is easy to use, customizable and lightweight. In this tutorial, we will be installing Flarum on NixOS Latest.
Prerequisites
Before you start installing Flarum, make sure you have the following prerequisites:
- NixOS Latest installed on your system
- Sudo access to the system
- A domain name or a public IP address to access the Flarum installation
- Basic knowledge of Linux commands
Step 1: Install Flarum using Nix
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.
Step 2: Create a Systemd Service for Flarum
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.
Step 3: Create a User and Directory for Flarum
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
Step 4: Configure Nginx for 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
Step 5: Install Flarum Dependencies
Install the required PHP extension for Flarum using the following command:
sudo nix-env -iA nixos.php74Extensions.php74-pdo_sqlite
Step 6: Setup Flarum
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.
Step 7: Start Flarum Service
Start the Flarum service using the following command:
sudo systemctl start flarum
Enable the Flarum service to start at boot:
sudo systemctl enable flarum
Conclusion
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.