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
-
Install Docker
sudo apt install docker.io apparmor-utils -y
-
Start the Docker service and enable it to start on boot:
sudo systemctl start docker sudo systemctl enable docker
-
Verify the installation by checking the Docker version:
docker --version
-
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
- Install PostgreSQL:
sudo apt install postgresql postgresql-contrib -y
- Start the PostgreSQL service and enable it to start on boot:
sudo systemctl start postgresql
sudo systemctl enable postgresql
- Verify the PostgreSQL Version (note it down for future reference):
psql --version
Step 1.3 - Install Redis
- Install Redis:
sudo apt install redis-server -y
- Open the Redis configuration file for editing:
sudo nano /etc/redis/redis.conf
- Find the line that starts with supervised, uncomment it if needed, and change its value to systemd:
Save and close the file (
supervised systemd
Ctrl
+X
, thenY
, then Enter). - Restart the Redis service to apply the changes:
sudo systemctl restart redis-server
- Enable Redis to start on boot:
sudo systemctl enable redis-server
- Verify that Redis is running:
systemctl status redis-server
Step 1.4 - Install NGINX
- Install Nginx:
sudo apt install nginx -y
- 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.
-
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
) -
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.
-
-
Verify DNS Propagation:
DNS changes may take some time to propagate worldwide (typically up to 48 hours). You can use online tools like
dig
ornslookup
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:
- Change into a directory that is accessible to the
postgres
usercd /tmp
- Check the server encoding:
sudo -u postgres psql -c 'SHOW SERVER_ENCODING'
- Create a PostgreSQL user and database:
sudo -u postgres createuser -P pretix sudo -u postgres createdb -O pretix pretix
- 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):Modify thesudo nano /etc/postgresql/<version>/main/postgresql.conf
listen_addresses
line:listen_addresses = 'localhost,172.17.0.1'
- Allow network connections by adding a new line to
pg_hba.conf
:Add the following line:sudo nano /etc/postgresql/<version>/main/pg_hba.conf
host pretix pretix 172.17.0.1/16 md5
- Restart PostgreSQL to apply changes:
sudo systemctl restart postgresql
Step 3.3 - Configure Redis
-
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
, thenY
, then Enter). -
Restart the Redis service:
sudo systemctl restart redis-server
-
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
-
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
-
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
, thenY
, 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
-
Pull the latest stable Pretix image from Docker Hub:
docker pull pretix/standalone:stable
-
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. - Adjust
-
Reload systemd to apply the new service configuration:
sudo systemctl daemon-reload
-
Enable the Pretix service to start on boot:
sudo systemctl enable pretix
-
Start the Pretix service:
sudo systemctl start pretix
-
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:
-
Edit your crontab configuration:
crontab -e
-
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
).
- Adjust the timing (
-
Save and exit the crontab editor.
Step 5 - Setup SSL
Step 5.1 Obtain SSL Certificates with Certbot
-
Install Certbot and the Nginx plugin:
sudo apt install certbot python3-certbot-nginx -y
-
Run Certbot to obtain SSL certificates for your domain (
pretix.example.com
). Replacepretix.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.
-
Certbot will place the obtained certificates in
/etc/letsencrypt/live/pretix.example.com/
. Note down the paths tofullchain.pem
(certificate chain) andprivkey.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:
-
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
andssl_certificate_key
point to the correct paths offullchain.pem
andprivkey.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; } }
- Replace
-
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
-
Test the Nginx configuration for syntax errors:
sudo nginx -t
-
If the configuration test is successful, reload Nginx to apply the changes:
sudo systemctl reload nginx
-
Verify that Nginx is running and serving Pretix over HTTPS:
systemctl status nginx
Step 6 - Access and Start Using Pretix
-
Open your web browser and navigate to:
https://pretix.example.com/control/
-
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.
-
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". -
Create your first event by navigating to the "Events" section and clicking on "Create a new event."
-
Follow the guided steps to set up your event details, ticket types, pricing, and any additional settings.
-
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