Linux Tutorials

Install Askbot Q&A Forum on Ubuntu 24.04

Askbot is an open-source question and answer platform built with Django and Python. It works like Stack Overflow – users post questions, others answer, and the community votes to surface the best answers. Askbot supports tagging, reputation systems, moderation tools, and email notifications out of the box. The project is actively maintained with the latest release (0.12.8) supporting Django 4.2 and Python 3.10+.

Original content from computingforgeeks.com - post 2659

This guide walks through installing Askbot on Ubuntu 24.04 LTS with PostgreSQL as the database backend, Nginx as a reverse proxy, Gunicorn as the application server, and a free SSL certificate from Let’s Encrypt. The same steps work on Ubuntu 22.04 with minor adjustments.

Prerequisites

Before starting, make sure you have the following ready:

  • A server running Ubuntu 24.04 LTS with at least 2 GB RAM and 2 CPU cores
  • Root or sudo access to the server
  • A domain name pointed to your server’s public IP (for SSL setup)
  • Ports 80 (HTTP) and 443 (HTTPS) open in your firewall

Step 1: Install Python and Pip

Ubuntu 24.04 ships with Python 3.12 by default, which meets Askbot’s requirement of Python 3.10 or newer. Install the Python development headers, pip, and the virtual environment package.

sudo apt update
sudo apt install -y python3 python3-pip python3-venv python3-dev build-essential

Confirm the Python version installed on your system.

python3 --version

The output should show Python 3.12.x or newer:

Python 3.12.3

Step 2: Create a Python Virtual Environment

Running Askbot inside a virtual environment keeps its dependencies isolated from system Python packages. Create a dedicated directory and virtual environment for the Askbot installation.

sudo mkdir -p /opt/askbot
sudo python3 -m venv /opt/askbot/venv

Activate the virtual environment and upgrade pip to the latest version.

source /opt/askbot/venv/bin/activate
pip install --upgrade pip setuptools wheel

Step 3: Install Askbot Q&A Forum

With the virtual environment active, install Askbot and its dependencies from PyPI. The setuptools-rust package is needed for building some of Askbot’s dependencies. Also install psycopg2-binary for PostgreSQL connectivity and gunicorn for serving the application.

pip install setuptools-rust
pip install askbot psycopg2-binary gunicorn

Verify that Askbot installed correctly by checking its version.

pip show askbot | grep Version

You should see the installed version confirmed:

Version: 0.12.8

Step 4: Set Up PostgreSQL Database

Askbot supports PostgreSQL, MySQL, SQLite, and Oracle as database backends. PostgreSQL is the recommended choice for production deployments. If you do not have PostgreSQL installed on Ubuntu, install it now.

sudo apt install -y postgresql postgresql-contrib

Start and enable the PostgreSQL service so it runs on boot.

sudo systemctl enable --now postgresql

Create a database and user for Askbot. Replace StrongPassword123 with a secure password of your choice.

sudo -u postgres psql -c "CREATE USER askbot WITH PASSWORD 'StrongPassword123';"
sudo -u postgres psql -c "CREATE DATABASE askbotdb OWNER askbot;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE askbotdb TO askbot;"

Verify the database was created successfully.

sudo -u postgres psql -c "\l" | grep askbot

The output should list the askbotdb database with askbot as the owner:

 askbotdb  | askbot | UTF8     | C.UTF-8 | C.UTF-8 |

Step 5: Initialize Askbot Project

The askbot-setup command generates a Django project directory with all the configuration files Askbot needs. Make sure the virtual environment is still active, then run the setup with database parameters.

source /opt/askbot/venv/bin/activate
askbot-setup -r /opt/askbot/site -e postgresql -d askbotdb -u askbot -p 'StrongPassword123' --db-host localhost --db-port 5432

This creates the project files under /opt/askbot/site. The key files generated include:

  • /opt/askbot/site/askbot_site/settings.py – Main Django settings file
  • /opt/askbot/site/manage.py – Django management script

Step 6: Run Database Migrations

With the project initialized and the database configured, run Django’s migration command to create all the required database tables.

cd /opt/askbot/site
python manage.py migrate

The migration output will show each app’s tables being created. After migrations finish, collect the static files that Askbot needs for the web interface.

python manage.py collectstatic --noinput

You should see a message confirming that static files were copied to the static directory:

xxx static files copied to '/opt/askbot/site/static'.

Step 7: Configure Gunicorn Application Server

Gunicorn serves as the WSGI application server that handles Python requests from Nginx. Create a dedicated system user to run the Askbot service.

sudo useradd --system --no-create-home --shell /usr/sbin/nologin askbot
sudo chown -R askbot:askbot /opt/askbot

Create a Gunicorn configuration file for Askbot.

sudo vi /opt/askbot/gunicorn_config.py

Add the following Gunicorn settings. Adjust the number of workers based on your CPU count – the formula is (2 x CPU cores) + 1.

bind = "unix:/opt/askbot/askbot.sock"
workers = 3
timeout = 120
user = "askbot"
group = "askbot"
accesslog = "/var/log/askbot/gunicorn-access.log"
errorlog = "/var/log/askbot/gunicorn-error.log"
loglevel = "info"

Create the log directory for Gunicorn.

sudo mkdir -p /var/log/askbot
sudo chown askbot:askbot /var/log/askbot

Step 8: Create a Systemd Service for Askbot

A systemd service ensures Askbot starts automatically on boot and can be managed with standard systemctl commands. Create the service unit file.

sudo vi /etc/systemd/system/askbot.service

Add the following service configuration.

[Unit]
Description=Askbot Q&A Forum (Gunicorn)
After=network.target postgresql.service
Requires=postgresql.service

[Service]
User=askbot
Group=askbot
WorkingDirectory=/opt/askbot/site
Environment="PATH=/opt/askbot/venv/bin"
ExecStart=/opt/askbot/venv/bin/gunicorn askbot_site.wsgi:application -c /opt/askbot/gunicorn_config.py
ExecReload=/bin/kill -s HUP $MAINPID
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Reload systemd, then enable and start the Askbot service.

sudo systemctl daemon-reload
sudo systemctl enable --now askbot

Check that the service is running without errors.

sudo systemctl status askbot

The output should show the service as active (running):

● askbot.service - Askbot Q&A Forum (Gunicorn)
     Loaded: loaded (/etc/systemd/system/askbot.service; enabled; preset: enabled)
     Active: active (running) since ...
   Main PID: 12345 (gunicorn)
     CGroup: /system.slice/askbot.service
             ├─12345 /opt/askbot/venv/bin/python /opt/askbot/venv/bin/gunicorn ...
             ├─12346 /opt/askbot/venv/bin/python /opt/askbot/venv/bin/gunicorn ...
             └─12347 /opt/askbot/venv/bin/python /opt/askbot/venv/bin/gunicorn ...

Step 9: Configure Nginx as Reverse Proxy

Nginx sits in front of Gunicorn to handle SSL termination, serve static files directly, and proxy application requests. Install Nginx if it is not already on your server.

sudo apt install -y nginx

Create a new Nginx server block for Askbot. Replace qa.example.com with your actual domain name.

sudo vi /etc/nginx/sites-available/askbot

Add the following Nginx configuration.

server {
    listen 80;
    server_name qa.example.com;

    # Redirect all HTTP to HTTPS after SSL is set up
    # return 301 https://$host$request_uri;

    location /static/ {
        alias /opt/askbot/site/static/;
        expires 30d;
        add_header Cache-Control "public, immutable";
    }

    location /media/ {
        alias /opt/askbot/site/askbot/upfiles/;
        expires 30d;
    }

    location / {
        proxy_pass http://unix:/opt/askbot/askbot.sock;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 120;
        proxy_connect_timeout 120;
    }
}

Enable the site and test the Nginx configuration for syntax errors.

sudo ln -s /etc/nginx/sites-available/askbot /etc/nginx/sites-enabled/
sudo nginx -t

If the syntax test passes, restart Nginx to apply the new configuration.

sudo systemctl restart nginx
sudo systemctl enable nginx

At this point, Askbot should be accessible at http://qa.example.com in your browser.

Step 10: Secure Askbot with Let’s Encrypt SSL

A free SSL certificate from Let’s Encrypt encrypts traffic between your users and the server. Install Certbot and the Nginx plugin.

sudo apt install -y certbot python3-certbot-nginx

Run Certbot to obtain and automatically configure the SSL certificate for your domain. Replace qa.example.com with your domain and provide a valid email address.

sudo certbot --nginx -d qa.example.com --non-interactive --agree-tos -m [email protected]

Certbot will modify your Nginx configuration to listen on port 443 with SSL and set up automatic HTTP to HTTPS redirection. Verify the certificate was installed correctly.

sudo certbot certificates

The output should list your domain with the certificate path and expiry date:

Certificate Name: qa.example.com
    Domains: qa.example.com
    Expiry Date: 2026-06-20 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/qa.example.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/qa.example.com/privkey.pem

Certbot sets up automatic renewal via a systemd timer. Confirm the renewal timer is active.

sudo systemctl status certbot.timer

The timer should show as active, meaning certificates will renew automatically before expiry:

● certbot.timer - Run certbot twice daily
     Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; preset: enabled)
     Active: active (waiting) since ...

Step 11: Configure UFW Firewall

Ubuntu 24.04 includes UFW (Uncomplicated Firewall) by default. Allow SSH, HTTP, and HTTPS traffic through the firewall.

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable

Verify the firewall rules are active and the correct ports are open.

sudo ufw status

The output should show SSH (port 22), HTTP (port 80), and HTTPS (port 443) allowed:

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Nginx Full                 ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
Nginx Full (v6)            ALLOW       Anywhere (v6)

Step 12: Update Askbot Settings for Production

Before going live, update the Askbot Django settings for production use. Open the settings file.

sudo vi /opt/askbot/site/askbot_site/settings.py

Find and update these key settings. Replace qa.example.com with your actual domain.

# Security settings for production
DEBUG = False
ALLOWED_HOSTS = ['qa.example.com']

# CSRF and session security
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True

# Static files
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/static/'

# Media files (user uploads)
MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'askbot', 'upfiles')
MEDIA_URL = '/media/'

After saving the settings, restart the Askbot service to pick up the changes.

sudo systemctl restart askbot

Open your browser and navigate to https://qa.example.com. You should see the Askbot Q&A forum homepage. The first user to register becomes the site administrator and can access the admin panel at /settings/ to customize the forum’s appearance, categories, and moderation rules.

Conclusion

You now have Askbot Q&A forum running on Ubuntu 24.04 with PostgreSQL, Gunicorn, Nginx, and Let’s Encrypt SSL. The setup uses a systemd service for automatic startup, a Unix socket for fast communication between Nginx and Gunicorn, and automatic SSL renewal via Certbot. For production hardening, consider setting up regular database backups, configuring email delivery for notifications, and placing the server behind a CDN for better performance. Check the Askbot GitHub repository for configuration options and updates.

Related Articles

Databases Install and Configure Redis Server on Ubuntu 24.04 / Debian 13 Databases Secure MySQL 8.4 LTS with TLS/SSL Certificates on Ubuntu 24.04 / Rocky Linux 10 Arch Linux Fix Slow SSH Login – Disable Reverse DNS Lookups on Linux Networking BIND vs Dnsmasq vs PowerDNS vs Unbound [Benchmark]

Leave a Comment

Press ESC to close