Setting Up a Pixelfed Instance
Pixelfed
Pixelfed is a web based, ethical photo sharing tool. The software is free and open source and contains no tracking, analytics or algorithms which seek to steer what you view. In this document I am going to attempt to get things going on my VPS, and it will eventually be available at https://pictures.yidhra.farm.
In this document I will generally follow the Pixelfed Instructions for running my own instance.
Pre-Requisites I Used
These are what I will be using:
Web Server
I already have Nginx installed and running, so made sense not to keep going with it. Pixelfed requires use of HTTPS URLs so HTTPS will need to be set up and working at least on perimeter.
Database
While Pixelfed supports several databases, I again have a Maria DB up and running so it made sense to choses that for me. I signed in as database administrator and set up database as follows, setting an actual password different from as indicated below.
PHP
Pixelfed requires PHP version 7.2 or better.
Check required modules are loaded by php. Output below reduced to show only required modules.
Apply desired upload limits by setting the appropriate values for the below in the php.ini file that your web server uses. In my case the correct file was located here: /etc/php/7.4/fpm/php.ini
.
post_max_size
(default 8M, set a little greated than max post size desired)file_uploads
(default On, which it needs to be)upload_max_filesize
(default 2M, set <= post_max_size)max_file_uploads
(default 20, must be >= your desired attachment limit)max_execution_time
(default 30, set up to 600 or > to avoid task interrupton)
Create User Account
Always a good idea to run services under dedicated accounts for the service. Create whatever account you wish.
Configure PHP-FPM Pool and Socket
I had to hunt around a little bit to find the location of the right directory, with /etc/php/7.4/fpm/pool.d
eventually turning out to be the needful, as Debian based instance. When all else fails check your php.ini file for path include=
is set to.
Create file and edit.
Make changes to ``pixelfed.conf` as below, adjusting as appropriate for user account, socket path and as needed to match your environment.
Configure Redis Socket
Find redis.conf
file for your server, usually in /etc/
or subdirectory of /etc
. And make changes as below to restrict network access and ensure both “redis” user and group have access to socket.
At this point all the foundational pre-requisite work is done and we can get down to the business of installing and configuring Pixelfed itself.
Setting up Pixelfed files
Download source via Git
Change to where you want to install the application code and clone from Github. I am running under a dedicated account for the application so I installed in the home directory of the account.
Set correct permissions
Change into the directory where the application was cloned from Github and set permissions. As I am using a dedicated account, I set the ownership to the account I am using.
Initialize PHP dependencies
The install process relies on the Composer dependency manager for PHP. Download and install, as it will be required to run against the files downloaded in the pixelfed folder.
Configure environment variables
Copy one of the provided sample .env files to .env for modification and use. The Pixelfed website has detailed information on each of the variable on the Configuration. Below I simply note the variables I set.
App variables
APP_NAME
- Use to set application name.APP_DEBUG
- Toggle debug information on or off.APP_URL
- Set url for instance.APP_DOMAIN
- Specify domain name to use.ADMIN_DOMAIN
- Same as used for APP_DOMAIN.SESSION_DOMAIN
- Same as used for ADMIN_DOMAIN.
Database variables
DB_CONNECTION
- Specify type of database, pgsql or mysql.DB_HOST
- Database hostname.DB_PORT
- Database portDB_DATABASE
- Database name.DB_USERNAME
- Database user name.DB_PASSWORD
- Database password.
Redis variables
REDIS_HOST
- Redis server host name.REDIS_PORT
- Redis server port.REDIS_PASSWORD
- Redis password.REDIS_SCHEME
- Set to unix for sockets, or tcp for ip network connection.REDIS_PATH
- path to socket if using.
Email variables
MAIL_FROM_ADDRESS
- Notification from address.MAIL_FROM_NAME
- Notification mail user name.MAIL_ENCRYPTION
- Specify mail encryption to use.MAIL_DRIVER
- Set as appropriate for mail solution.MAIL_HOST
- Specify mail server.MAIL_PORT
- Specify mail server port.MAIL_USERNAME
- Notification mail user for authentication.MAIL_PASSWORD
- Password associated with mail user.
Additional variables
IMAGE_DRIVER
- Specify image manipulation tool used.ACTIVITY_PUB
- Enable/disable federation.AP_REMOTE_FOLLOW
- Allow/prevent remote following.
Setting up services
One-time setup tasks
Job Queuing
Using Laravel Horizon
Create a systemd service unit so Pixelfed and supporting products are started at boot time and run in the background. Create pixelfed.service in /etc/systemd/system/.
Review and modify the above to match the install configuration of system paying specific attention to the following:
- Replacing
mariadb
withpostgresql
ormysql
. - Replacing
php-fpm
with distribution specific PHP-FPM package name, e.g.php7.3-fpm
. - Replacing
nginx
withapache
. - Replacing
Requires
withWants
if not running in a production environment. - Replacing
/usr/bin/php
or/usr/share/webapps/pixelfed/artisan
with the correct paths. - Replacing
User=http
to reflect the app user, e.g.User=pixelfed
. Alternatively comment this line in order to run in the system slice.
Once file is correct, start the service.
Scheduling periodic tasks
Paste the following into crontab, correcting paths as needed to match install.
Handling web requests
Nginx
Pixelfed includes a sample NGINX configuration at contrib/nginx.conf
. You can copy the contents of this file or include it within your nginx.conf
. Review comments, setting correct domain nme and paths.
- FastCGI path - Make sure to use the correct
fastcgi_pass
socket path for your distribution and version of PHP-FPM. - If you have configured a PHP server over TCP, you may also pass to its IP and port,
localhost:9000
by default. - Nginx web root - Make sure to use the
/public
folder as your server root. Example:server {root /var/www/pixelfed/public;}
. If you set root to the install directory (Example:server {root /var/www/pixelfed;}
Pixelfed will not work.
Use certbot
to get an HTTPS certificate and then you should be off to the races with your Pixelfed instance.