Running Pixelfed on FreeBSD Guide

Preface

This guide is heavily based on Stefano Marinelli’s FreeBSD Mastodon Guide. Thank your for giving me permission to use your guide as a base!

Introduction

Pixelfed is a free and open-source image sharing social network service. The platform uses a decentralized architecture which is roughly comparable to e-mail providers, meaning user data is not stored on one central server “Server (computing)”). It uses the ActivityPub protocol, allowing users to interact with other social networks within the protocol, such as MastodonPeerTube, and Friendica. Pixelfed and other platforms utilizing this protocol are considered to be part of the Fediverse. Wikipedia

This guide aims to provide a comprehensive walkthrough for installing Pixelfed on a FreeBSD jail, managed by BastilleBSD. While Pixelfed documentation tends to be Linux-centric, this tutorial fills the gap for FreeBSD users.

Note: This guide describes a simple, single-jail installation. For production environments, it’s recommended to separate services (Valkey, PostgreSQL, etc.) into individual jails. This tutorial assumes a basic understanding of FreeBSD and Unix-like systems.

Prerequisites

  • A FreeBSD system with BastilleBSD installed
  • Basic knowledge of FreeBSD jail management
  • Familiarity with command-line operations

Step 1: Creating the Jail

Let’s start by creating a new jail using BastilleBSD:

Step 2: Configuring the Jail

As we’ll be installing PostgreSQL in the jail, we need to add some configurations to the jail’s jail.conf:

After adding these lines, restart the jail:

Step 3: Installing Dependencies

Now, let’s install the necessary packages:

Step 4: Enabling and Configuring Services

Enable Valkey, Nginx, php_fpm and PostgreSQL:

Valkey Configuration

For simplicity in this jail environment, we’ll disable Valkey’s protected mode. However, this is not recommended for production environments without proper security measures.

Edit /usr/local/etc/valkey.conf and set:

Important: In a production environment, ensure proper authentication and network security measures are in place before disabling protected mode.

PostgreSQL Initialization and Configuration

Initialize the PostgreSQL database:

Modify PostgreSQL to accept connections from the jail’s services. Edit /var/db/postgres/data16/pg_hba.conf and add:

Note: In a production environment, consider using more restrictive authentication methods.

Start PostgreSQL and Valkey:

Step 5: Database Setup

Create the Pixelfed database user:

Step 6: Creating the Pixelfed User

Create a dedicated user for Pixelfed:

Step 7: Installing Pixelfed

Switch to the Pixelfed user and install the software:

Download source via Git 

Initialize PHP dependencies 

Run composer install to fetch the dependencies needed by Pixelfed. It is recommended to run with the following flags:

Step 8: Pixeled Setup

Configure environment variables

Please consult the official installation guide for this Pixelfed :: Configure environment variables.

Setting up services

One-time setup tasks 

One time only, you need to generate the secret APP_KEY:

One time only, the storage/ directory must be linked to the application:

Database migrations must be run:

If you want to enable support for location data:

If you enabled ActivityPub federation:

If you enabled OAuth:

Routes should be cached whenever the source code changes or whenever you change routes:

Every time you edit your .env file, you must run this command to have the changes take effect:

Job queueing

If you want admins to be able to access the Horizon web dashboard, you will need to run the following commands:

Scheduling periodic tasks 

The task scheduler is used to run periodic commands in the background, such as media optimization, garbage collection, and other time-based tasks that should be run every once in a while.

To set up scheduled tasks using Cron:

Paste the following cronjob into your crontab:

Step 9: Nginx and php_fpm Configuration

This example assumes that you are using a secure reverse proxy which will handle the encryption part. Nginx as well as php_fpm will run as the pixelfed user.
In case of nginx of is necessary because the upload directories are created with restrictive permissions and that can only be changed by changing the code (at which the Pixelfed developer pointed me).

Furthermore you need to create a php_fpm configuration (in /usr/local/etc/php-fpm.d/) – e.g. pixelfed.conf

Step 10: Creating FreeBSD RC Scripts

Create a file /usr/local/etc/rc.d/pixelfed containing, add execute permissions to it and enable it.

Conclusion

Restart the jail or start the services individually. Logs will be appended to /var/log/messages.

You now have a functioning Mastodon instance running in a FreeBSD jail. All services are run by the “daemon” user and are supervised.

Remember to regularly update your Pixelfed instance and monitor its performance. For production environments, consider implementing additional security measures and potentially separating services into individual jails.

Enjoy your new Pixelfed instance!