Bare-metal Madblog installation on an Ubuntu/Debian Server with Apache2 as Webserver
Set up Madblog, the federated blogging platform that serves blogposts from Markdown-files, on an Ubuntu or Debian Server
Madblog is a blogging platform that presents your blogposts straight from files written in Markdown, there is no need for a DB, the filesystem is you DB engine so to say. Madblog supports Webmention and federation via ActivityPub.
Madblog is very well documented by it's author Fabio Manganiello in his blogpost about Madblog and even more so in the README.md that comes with Madblog's source code.
Madblog is running my blog since a few days. In this post I describe how I have set up the software on an Ubuntu Server using Apache2 webserver to serve the blog to the internet. This description is for a bare-metal install of Madblog so it is not covering an installation using a Docker container.
Assumptions and Preparations
I installed Madblog on an Ubuntu Server 26.04 machine but I asume that the following instructions also work on older releases of Ubuntu.
Regarding Debian, most to all things said here apply to Debian Trixie as well, so the steps in this instruction should be valid for a Debian Server without any change.
All following commands need to be executed as root. So change your user to root or prepend a sudo to all following commands.
As a first step, make sure your system has the latest package versions installed.
$ apt update
$ apt dist-upgrade
If they are not already part of your installation, you need to install Apache2 webserver, the python package installer pip and the package for python3 virtual environments.
$ apt install apache2 python3-pip python3-venv
Next, create a dedicated non-login madblog user and directories for configuration, Markdown posts and images.
$ useradd --system --home-dir /var/lib/madblog --create-home --shell /usr/sbin/nologin madblog
$ mkdir -p /etc/madblog /var/lib/madblog/content/markdown /var/lib/madblog/content/img
$ chown -R madblog:madblog /etc/madblog /var/lib/madblog
If you want to show a favicon for your blog, you can drop a favicon.ico file into /var/lib/madblog/content/img.
Creating a virutal environment for Python
If you would install Python packages globalby on your Ubuntu server you would get into conflict with the package managing system of your server that handles already several python pagages through apt, as you can see when you check the output of apt list --installed|grep python.
In order to get out of the way of apt we will install Madblog into a virtual python environment.
Create a virtual environment inside /var/lib/madblog/venv and upgrade the pip installed in there. Note: now you must act as the madblog user, so sudo -u madblog is appended to the following commands.
$ sudo -u madblog python3 -m venv /var/lib/madblog/venv
$ sudo -u madblog /var/lib/madblog/venv/bin/pip install --upgrade pip
Quick side note: How Madblog is run on a production site
Madblog is written in Python and uses Flask as a web framework. Installing Madblog and executing madblog within the folder with your posts in Markdown will serve those posts on port 8000. But this is rather for test purposes than for production.
Flask apps handle all contact to the outside world through Web Server Gateway Interface (WSGI). In order to serve the Flask app a WSGI-capable server is needed. This is where Gunicorn comes into play. If you want to learn more check out how to deploy Flask apps. While Gunicorn does a great job serving WSGI-apps it is not designed to handle traffic on the internet. It requires a fast local connection so it needs to be run behind a proxy server that serves the internet and can handle slow clients well. That's why we need a full fledged webserver like Apache2 as a proxy in front of gunicorn. Let's keep that in mind when we continue with the installation.
Installing Madblog and Gunicorn
Now we are installing Madblog and Gunicorn into the virtual environment by using the pip version we installed in the previous step.
$ sudo -u madblog /var/lib/madblog/venv/bin/pip install madblog gunicorn
This pulls in and installs a bunch of packages. Besides the gunicorn and madblog packages also further packages that madblog depends on, like flask, markdown, webmentions, and pubby, to mention a few. The last two, webmentions and pubby, are libraries that make Madblog a social and federated blog, by the way. They are both written by Madblog's author Fabio.
Configuration
Now we need to configure Madblog. Create config.yaml below /etc/madblog/. You can start off with the example configuration file config.example.yaml from the Madblog repository. Checkout the Configuration section in Madblog's readme for the options that can be used in the config file. You should at least set title, link and description. Setting logo to the URL of a nice logo image is also a good idea.
With setting enable_webmentions: to true you enable Webmention. enable_activitypub: true enables federation via ActivityPub.
A minimal working configuration could look like this:
title: "My Blog"
description: "Notes and essays"
link: "https://blog.example.com"
# enable Webmention
enable_webmentions: true
# enable ActivityPub federation (creates handle @blog@blog.example.com)
enable_activitypub: true
Note: Additionally to setting options in the config-file you can set all of Madblog's options as well by using environment variables. Each option has an environment variable associated by appending "madblog_" to it's name. For example, option title can be set by environment variable madblog_title. That's how I have set content_dir in the next section.
Using systemd to glue Gunicorn and Madblog together
Gunicorn serving Madblog is a service that should start up at boot time. So let's give control to systemd.
Create a madblog.service file in /var/lib/madblog/.
$ cd /var/lib/madblog
$ touch madblog.service
Create a softlink to that file from /etc/systemd/system.
$ cd /etc/systemd/system
$ ln -s /var/lib/madblog/madblog.service madblog.service
Now edit madblog.service as follows.
[Unit]
Description=Madblog Gunicorn WSGI Daemon
After=network.target
[Service]
User=madblog
Group=madblog
WorkingDirectory=/var/lib/madblog
Environment="MADBLOG_CONFIG=/etc/madblog/config.yaml"
Environment="MADBLOG_CONTENT_DIR=/var/lib/madblog/content"
Environment="PATH=/var/lib/madblog/venv/bin:/usr/local/bin:/usr/bin:/bin"
ExecStart=/var/lib/madblog/venv/bin/gunicorn --preload -w 4 -b 127.0.0.1:8000 madblog.uwsgi
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
You can see that both config and content directories are set through environment variables and gunicorn is called to open Madblog (or rather the file uwsgi.py in the madblog folder within the virtual environment). Once running, the service is reachable at port 8000 on the localhost. Gunicorn spawns four workers and preloads Madblog into memory before doing so.
Starting Madblog
After reloading the systemd manager configuration Madblog is ready to be started.
$ systemctl daemon-reload
$ systemctl enable --now madblog
You can check Madblog's status with
$ systemctl status madblog
In the output you should see something like Active: active (running) since ... if the Madblog app is running correctly.
Now you should be able to check Madblog's output when connecting to port 8000 on localhost with a webbrowser. If you only have access to the localhost via ssh you can try to check with a textbrowser like [lynx](https://en.wikipedia.org/wiki/Lynx_(web_browser)).
Serving Madblog to the Internet
If you can reach Madblog on Port 8000 of your server internaly you are ready to serve Madblog to the internet.
Create a conf-file for Madblog as a new virtual host in /etc/apache2/sites-available/
$ touch /etc/apache2/sites-available/madblog.conf
Fill in the following and don't forget to fill in your hostname.
<VirtualHost *:80>
ServerName blog.example.com
# Redirect http traffic to https
Redirect permanent / https://blog.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName blog.example.com
# Enable SSL for this virtual host.
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/fullchain.pem
SSLCertificateKeyFile /etc/apache2/ssl/privkey.pem
SSLCertificateChainFile /etc/apache2/ssl/fullchain.pem
# Preserve the hostname
ProxyPreserveHost On
# Tell the backend we used https
RequestHeader set X-Forwarded-Proto "https"
# Forward traffic to the internal non-SSL service
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/
ErrorLog ${APACHE_LOG_DIR}/madblog-error.log
CustomLog ${APACHE_LOG_DIR}/madblog-access.log combined
</VirtualHost>
Note: the virtual host configuration above assumes that you are using TLS/SSL, i.e. https with the SSL certificates available at the above locations.
Once saved, enable the site, check the config-syntax and restart Apache2.
$ a2ensite blog.example.com
$ apache2ctl configtest
$ systemctl reload apache2
Your blog powered by Madblog is now reachable at https://blog.example.com
Reactions
How to interact with this page
Webmentions
To interact via Webmentions, send an activity that references this URL from a platform that supports Webmentions, such as Lemmy, WordPress with Webmention plugins, or any IndieWeb-compatible site.
ActivityPub
- Follow @mafeu@martin.feuersaenger.de on your ActivityPub platform (e.g. Mastodon, Misskey, Pleroma, Lemmy).
- Mention @mafeu@martin.feuersaenger.de in a post to feature on the Guestbook.
- Search for this URL on your instance to find and interact with the post.
- Like, boost, quote, or reply to the post to feature your activity here.