How to Install Friendica on NixOS Latest

In this tutorial, we will be guiding you through the installation process of Friendica, which is a free and open-source social networking platform. The installation process in this tutorial will be carried out on NixOS Latest, so make sure you have NixOS Latest installed on your system before proceeding.

Step 1: Update the system

Before installing any package, it is essential to update and upgrade the system to ensure that all the packages are up-to-date. Run the following commands to update your system:

sudo nix-channel --update
sudo nixos-rebuild switch

Step 2: Installing the required packages

Next, we will proceed with installing the required packages which include nginx, php, and mariadb. Open your terminal and run the following command to install the packages:

sudo nix-env -iA nixos.nginx nixos.php mariadb

Step 3: Configuring the Nginx server

After the installation of the required packages, we will now configure the Nginx server to make it compatible with the Friendica platform. Open the Nginx configuration file located in the /etc/nixos/ directory using any text editor of your choice:

sudo nano /etc/nixos/nginx.conf

Paste the following configuration at the end of the file:

server {
        listen 80;
        server_name your-domain.com;
        root /var/www/friendica;

        index index.php;

        location / {
                try_files $uri $uri/ /index.php?q=$request_uri;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PHP_VALUE "session.save_path = /tmp";
                fastcgi_param QUERY_STRING $query_string;
                fastcgi_param REQUEST_METHOD $request_method;
                fastcgi_param CONTENT_TYPE $content_type;
                fastcgi_param CONTENT_LENGTH $content_length;
                fastcgi_intercept_errors on;
                fastcgi_buffer_size 16k;
                fastcgi_buffers 4 16k;
                fastcgi_connect_timeout 300;
                fastcgi_send_timeout 300;
                fastcgi_read_timeout 300;
                include /etc/nixos/fastcgi.conf;
        }

        location ~ /\.ht {
                deny all;
        }
}

Make sure to replace your-domain.com with your domain name. Save and close the file.

Step 4: Creating the Friendica database

To create the Friendica database, run the following command:

sudo mysql -uroot -p < /var/www/friendica/addons/database.sql

You will be prompted to enter your root password. Once entered, the database will be created.

Step 5: Downloading and installing Friendica

Download Friendica from the official website using the following command:

sudo wget https://github.com/friendica/friendica/archive/master.zip -O /var/www/friendica.zip

Unzip the downloaded file using the following command:

sudo unzip /var/www/friendica.zip -d /var/www/

Rename the unzipped directory with the following command:

sudo mv /var/www/friendica-master /var/www/friendica

Change the ownership and permission of the friendica directory using the following command:

sudo chown -R nginx:nginx /var/www/friendica
sudo chmod -R 755 /var/www/friendica

Step 6: Configuring Friendica

Navigate to the config directory within the friendica directory using the following command:

cd /var/www/friendica/config/

Copy the config.php.sample file to a new file config.php using the following command:

cp config.php.sample config.php

Open the config.php file using a text editor and enter the following configuration details:

$config['system']['baseurl'] = 'http://your-domain.com';
$config['system']['sitename'] = 'Your Site Name';
$config['system']['admin_email'] = '[email protected]';
$config['config']['dbtype'] = 'mysql';
$config['config']['dbhost'] = 'localhost';
$config['config']['dbname'] = 'friendica';
$config['config']['dbuser'] = 'root';
$config['config']['dbpass'] = 'root-password';

Make sure to replace the domain name and other details with your own.

Step 7: Starting and enabling services

Finally, start and enable the services using the following commands:

sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
sudo systemctl start mariadb
sudo systemctl enable mariadb

Final Thoughts

Congratulations! You have successfully installed Friendica on NixOS Latest. You can now visit your website by entering the domain name in your web browser.