Get Rewarded! We will reward you with up to €50 credit on your account for every tutorial that you write and we publish!

Setting Up Pretix

profile picture
Author
bitsoderso
Published
2024-07-08
Time to read
12 minutes reading time

Introduction

Pretix is a versatile, open-source ticket sales software designed to help you manage event ticketing with ease and flexibility. Whether you are organizing a small local event or a large-scale international conference, Pretix offers a comprehensive set of features to streamline the entire ticketing process.

Prerequisites

  • Server with Debian 12
    • Access to root user or user with sudo permissions
    • SSH key in ~/.ssh/authorized_keys to access the server
    • Firewall that allows port 80 (HTTP) and port 443 (HTTPS) for incoming traffic (inbound rules)
  • Basic knowledge of SSH and Docker
  • Domain name or subdomain that you can pointed to your server's IP address (A and AAAA Record)
  • A SMTP server to send out mails

Example terminology

  • User: holu
  • Domain: example.com
  • Server public IP: <203.0.113.1>

Step 1 - Configure the Server and Install Prerequisites

  • Connect to your server using SSH:

    ssh holu@<203.0.113.1>
  • Update your server to the latest packages:

    sudo apt update && sudo apt upgrade -y
  • Set the time zone

    Setting the correct time zone on your server ensures that your system logs and scheduled tasks are in sync with your local time.

    List available time zones, find your desired time zone from the list, and set it (replace Region/City with your time zone, e.g., Europe/Berlin):

    timedatectl list-timezones
    sudo timedatectl set-timezone Region/City

    Verify that the time zone has been set correctly:

    timedatectl

    You should see your newly set time zone in the output.

Step 1.1 - Install Docker

  1. Install Docker

    sudo apt install docker.io apparmor-utils -y
  2. Start the Docker service and enable it to start on boot:

    sudo systemctl start docker
    sudo systemctl enable docker
  3. Verify the installation by checking the Docker version:

    docker --version
  4. Add your user to the docker group

    sudo usermod -aG docker holu

    You might need to log out and back in afterwards, to update your groups.

Step 1.2 - Install PostgreSQL

  1. Install PostgreSQL:
    sudo apt install postgresql postgresql-contrib -y
  2. Start the PostgreSQL service and enable it to start on boot:
    sudo systemctl start postgresql
    sudo systemctl enable postgresql
  3. Verify the PostgreSQL Version (note it down for future reference):
    psql --version

Step 1.3 - Install Redis

  1. Install Redis:
    sudo apt install redis-server -y
  2. Open the Redis configuration file for editing:
    sudo nano /etc/redis/redis.conf
  3. Find the line that starts with supervised, uncomment it if needed, and change its value to systemd:
    supervised systemd
    Save and close the file (Ctrl+X, then Y, then Enter).
  4. Restart the Redis service to apply the changes:
    sudo systemctl restart redis-server
  5. Enable Redis to start on boot:
    sudo systemctl enable redis-server
  6. Verify that Redis is running:
    systemctl status redis-server

Step 1.4 - Install NGINX

  1. Install Nginx:
    sudo apt install nginx -y
  2. Verify that Nginx is running:
    systemctl status nginx

Step 2 - Add DNS Records for Your Domain

To direct traffic to your Pretix installation, you'll need to add DNS records (A and AAAA) for your domain. This step assumes you have access to your domain registrar's DNS management panel.

  1. Find Your Server's IP Address:

    To find your server's IP address, use the following command:

    ip a

    Look for the IP address associated with the network interface you are using (usually eth0 )

  2. Add DNS Records:

    Once you have your server's IP address, proceed to add DNS records:

    • A Record (IPv4): Points your domain to your server's IPv4 address.

      • Record Type: A
      • Host/Name: pretix
      • Value/IP Address: Your server's IPv4 address
    • AAAA Record (IPv6): Points your domain to your server's IPv6 address.

      • Record Type: AAAA
      • Host/Name: pretix
      • Value/IP Address: Your server's IPv6 address

    Save the DNS records after adding them.

  3. Verify DNS Propagation:

    DNS changes may take some time to propagate worldwide (typically up to 48 hours). You can use online tools like dig or nslookup to check if your DNS records have propagated:

    dig pretix.example.com A
    dig pretix.example.com AAAA

    Replace pretix.example.com with your actual domain name. If the returned IP addresses match your server's IP addresses, then DNS propagation is complete.

Step 3 - Setup Prerequisites

Step 3.1 Create Data Files Directory

First, create a directory on your server for Pretix to store its data files. Then, make this directory writable for the user that runs Pretix inside the Docker container:

sudo mkdir /var/pretix-data
sudo chown -R 15371:15371 /var/pretix-data

Step 3.2 Configure the Database

You need to create a database and a database user for Pretix. You can do this using any database management tool or directly via the database shell. Ensure UTF8 encoding for compatibility:

  1. Change into a directory that is accessible to the postgres user
    cd /tmp
  2. Check the server encoding:
    sudo -u postgres psql -c 'SHOW SERVER_ENCODING'
  3. Create a PostgreSQL user and database:
    sudo -u postgres createuser -P pretix
    sudo -u postgres createdb -O pretix pretix
  4. Ensure the database listens on the network. If PostgreSQL is on the same host as Docker but not inside a Docker container, update the postgresql.conf file (replace <version> with your PostgreSQL version):
    sudo nano /etc/postgresql/<version>/main/postgresql.conf
    Modify the listen_addresses line:
    listen_addresses = 'localhost,172.17.0.1'
  5. Allow network connections by adding a new line to pg_hba.conf:
    sudo nano /etc/postgresql/<version>/main/pg_hba.conf
    Add the following line:
    host    pretix          pretix          172.17.0.1/16           md5
  6. Restart PostgreSQL to apply changes:
    sudo systemctl restart postgresql

Step 3.3 - Configure Redis

  1. Edit the Redis configuration file:

    sudo nano /etc/redis/redis.conf

    Add the following lines to enable Unix sockets:

    unixsocket /var/run/redis/redis.sock
    unixsocketperm 777

    Save and close the file (Ctrl+X, then Y, then Enter).

  2. Restart the Redis service:

    sudo systemctl restart redis-server
  3. To prevent systemd from deleting /var/run/redis on every Redis restart, edit the Redis service configuration:

    sudo systemctl edit redis-server

    Add the following lines in the editor that opens:

    [Service]
    RuntimeDirectoryPreserve=yes

    Save and close the editor.

Step 3.4 - Configure Pretix

  1. Create a config directory and file for Pretix:

    sudo mkdir /etc/pretix
    sudo touch /etc/pretix/pretix.cfg
    sudo chown -R 15371:15371 /etc/pretix/
    sudo chmod 0700 /etc/pretix/pretix.cfg
  2. Edit the configuration file /etc/pretix/pretix.cfg and add the following content, adjusting values to match your environment:

    Make sure you remove the comments before you save the file.

    [pretix]
    instance_name=My pretix installation
    url=https://pretix.example.com
    currency=EUR
    ; DO NOT change the following value, it has to be set to the location of the
    ; directory *inside* the docker container
    datadir=/data
    trust_x_forwarded_for=on
    trust_x_forwarded_proto=on
    
    [database]
    backend=postgresql
    name=pretix
    user=pretix
    ; Replace with the password you chose above for the database user "pretix"
    password=*********
    ; In most docker setups, 172.17.0.1 is the address of the docker host. Adjust
    ; this to wherever your database is running, e.g. the name of a linked container.
    host=172.17.0.1
    
    [mail]
    from=hello@localhost        ; Email address from which emails will be sent
    host=smtp.example.com       ; SMTP server hostname or IP address
    user=username               ; SMTP username (if authentication is required)
    password=your_password      ; SMTP password (if authentication is required)
    port=587                    ; SMTP port (typically 587 for TLS, 465 for SSL)
    tls=on                      ; Enable TLS/SSL encryption (use 'on' for TLS, 'off' for SSL)
    ssl=off                     ; Enable SSL (use 'on' for SSL, 'off' for TLS)
    
    [redis]
    location=unix:///var/run/redis/redis.sock?db=0
    ; Remove the following line if you are unsure about your redis' security
    ; to reduce impact if redis gets compromised.
    sessions=true
    
    [celery]
    backend=redis+socket:///var/run/redis/redis.sock?virtual_host=1
    broker=redis+socket:///var/run/redis/redis.sock?virtual_host=2

    After you adjusted the values and removed the comments, save and close the file (Ctrl+X, then Y, then Enter).

This configuration file (pretix.cfg) sets up Pretix with necessary parameters such as instance name, URL, currency, database connection details, email settings, Redis configuration, and Celery task queue configuration. Adjust values according to your specific setup and requirements.

Step 4 - Install Pretix

Step 4.1 - Configure Docker Image and Service

  1. Pull the latest stable Pretix image from Docker Hub:

    docker pull pretix/standalone:stable
  2. Create a systemd service file for Pretix: Create the file /etc/systemd/system/pretix.service with the following content:

    • Adjust -p 127.0.0.1:8345:80 to expose Pretix on the desired port (8345) on localhost.
    • This tutorial created /var/pretix-data and /etc/pretix. If you used different paths, make sure to change the paths in the file below accordingly.
    [Unit]
    Description=pretix
    After=docker.service
    Requires=docker.service
    
    [Service]
    TimeoutStartSec=0
    ExecStartPre=-/usr/bin/docker kill %n
    ExecStartPre=-/usr/bin/docker rm %n
    ExecStart=/usr/bin/docker run --name %n -p 127.0.0.1:8345:80 \
        -v /var/pretix-data:/data \
        -v /etc/pretix:/etc/pretix \
        -v /var/run/redis:/var/run/redis \
        --sysctl net.core.somaxconn=4096 \
        pretix/standalone:stable all
    ExecStop=/usr/bin/docker stop %n
    
    [Install]
    WantedBy=multi-user.target

    This service file ensures that Docker starts the Pretix container (pretix/standalone:stable) with necessary volumes and configurations.

  3. Reload systemd to apply the new service configuration:

    sudo systemctl daemon-reload
  4. Enable the Pretix service to start on boot:

    sudo systemctl enable pretix
  5. Start the Pretix service:

    sudo systemctl start pretix
  6. Verify the status of the Pretix service to ensure it started correctly:

    systemctl status pretix

Step 4.2 Configure Cronjob for Pretix

To automate management tasks in Pretix, set up a cronjob that runs the runperiodic management command at a specified interval. Here's how you can configure it:

  1. Edit your crontab configuration:

    crontab -e
  2. Add the following line to run the runperiodic command for Pretix:

    15,45 * * * * /usr/bin/docker exec pretix pretix runperiodic
    • Adjust the timing (15,45 * * * *) as per your preferred interval. This example runs the command at 15 and 45 minutes past every hour.
    • Ensure the user running the cronjob has permission to use the Docker daemon (docker exec).
  3. Save and exit the crontab editor.

Step 5 - Setup SSL

Step 5.1 Obtain SSL Certificates with Certbot

  1. Install Certbot and the Nginx plugin:

    sudo apt install certbot python3-certbot-nginx -y
  2. Run Certbot to obtain SSL certificates for your domain (pretix.example.com). Replace pretix.example.com with your actual domain:

    certbot certonly --nginx -d pretix.example.com
    • Certbot will interactively guide you through the process. Choose the option to expand existing coverage if you already have other SSL configurations.
    • Certbot will automatically configure Nginx to serve the challenges needed for validation, obtain the certificate, and update your Nginx configuration.
  3. Certbot will place the obtained certificates in /etc/letsencrypt/live/pretix.example.com/. Note down the paths to fullchain.pem (certificate chain) and privkey.pem (private key) for the next step.

Step 5.2 - Configure Nginx Proxy with SSL for Pretix

After obtaining the SSL certificates using Certbot, proceed with configuring Nginx as a reverse proxy for Pretix:

  1. Edit your Nginx configuration file (e.g., /etc/nginx/sites-available/pretix) and add the following content:

    • Replace pretix.example.com with your actual domain name.
    • Ensure ssl_certificate and ssl_certificate_key point to the correct paths of fullchain.pem and privkey.pem obtained from Certbot.
    server {
        listen 80 default_server;
        listen [::]:80 ipv6only=on default_server;
        server_name pretix.example.com;
    
        location / {
            return 301 https://$host$request_uri;
        }
    }
    
    server {
        listen 443 ssl default_server;
        listen [::]:443 ssl ipv6only=on default_server;
        server_name pretix.example.com;
    
        ssl_certificate /etc/letsencrypt/live/pretix.example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/pretix.example.com/privkey.pem;
    
        location / {
            proxy_pass http://localhost:8345;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;
            proxy_set_header Host $http_host;
        }
    }
  2. Enable the Nginx configuration by creating a symbolic link to sites-enabled and delete the default configuration:

    sudo ln -s /etc/nginx/sites-available/pretix /etc/nginx/sites-enabled/
    sudo rm -rf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
  3. Test the Nginx configuration for syntax errors:

    sudo nginx -t
  4. If the configuration test is successful, reload Nginx to apply the changes:

    sudo systemctl reload nginx
  5. Verify that Nginx is running and serving Pretix over HTTPS:

    systemctl status nginx

Step 6 - Access and Start Using Pretix

  1. Open your web browser and navigate to:

    https://pretix.example.com/control/
  2. Log in with the following credentials:

    • Username: admin@localhost
    • Password: admin

    Note: It is crucial to change the default password immediately after logging in for security reasons.

  3. Once logged in, create an organizer profile. This step is necessary before creating events and selling tickets. To add a new organizer, you need to navigate to "Organizer" and click on Admin mode at the top. This will enable the option + Create a new organizer. After the first organizer is added, you can end the "Admin mode".

  4. Create your first event by navigating to the "Events" section and clicking on "Create a new event."

  5. Follow the guided steps to set up your event details, ticket types, pricing, and any additional settings.

  6. Start selling tickets by enabling the event and sharing the ticket sales page with your audience.

Conclusion

You have successfully installed Pretix using Docker on your server. You can now start managing your event ticket sales with ease. For further customization and configuration, refer to the Pretix documentation.

This tutorial is based on the official Pretix documentation Official Pretix Documentation

License: MIT
Want to contribute?

Get Rewarded: Get up to €50 in credit! Be a part of the community and contribute. Do it for the money. Do it for the bragging rights. And do it to teach others!

Report Issue
Try Hetzner Cloud

Get €20/$20 free credit!

Valid until: 31 December 2025 Valid for: 3 months and only for new customers
Get started
Want to contribute?

Get Rewarded: Get up to €50 credit on your account for every tutorial you write and we publish!

Find out more