- add your doimain to settings "CSRF_TRUSTED_ORIGINS"
- Keep debug enabled to disable captcha
- Only test on python 3.11.0
DEBUG=True
SECRET_KEY=
ALLOWED_HOSTS=
STRIPE_SECRET_KEY=sk_live_
STRIPE_PUBLISHABLE_KEY=pk_live_
STRIPE_WEBHOOK_SECRET=
STRIPE_BILLING_PORTAL_URL=https://billing.stripe.com/
STRIPE_PUBLISHABLE_KEY_TEST=pk_test_
STRIPE_SECRET_KEY_TEST=sk_test_
STRIPE_WEBHOOK_SECRET_TEST=
PRICE_ID_MONTHLY=price_
PRICE_ID_YEARLY=price_
PRICE_ID_CUSTOM=price_
PRICE_ID_MONTHLY_TEST=price_
PRICE_ID_YEARLY_TEST=price_
PRICE_ID_CUSTOM_TEST=price_
DISCORD_LIVERY_REQUESTS_CHANNEL_WEBHOOK=https://discord.com/api/webhooks/
DISCORD_OPERATOR_TYPE_REQUESTS_CHANNEL_WEBHOOK=https://discord.com/api/webhooks/
DISCORD_TYPE_REQUEST_WEBHOOK=https://discord.com/api/webhooks/
DISCORD_FOR_SALE_WEBHOOK=https://discord.com/api/webhooks/
DISCORD_WEB_ERROR_WEBHOOK=https://discord.com/api/webhooks/
DISCORD_404_ERROR_WEBHOOK=https://discord.com/api/webhooks/
DISCORD_BOT_API_URL=http://localhost:8070
DISCORD_GUILD_ID=
DISCORD_BOT_API_TOKEN=
DISCORD_MIGRATION_ERROR_ID=
DISCORD_REPORTS_CHANNEL_ID=
DISCORD_LIVERY_ID=
DISCORD_GAME_ID=
DISCORD_OPERATOR_LOGS_ID=
DISCORD_GUILD_ID=
DISCORD_BOT_API_TOKEN=
DB_NAME=mybustimes
DB_USER=
DB_PASSWORD=
DB_HOST=
DB_PORT=
SMTP_HOST=
SMTP_PORT=
SMTP_USER=
SMTP_PASSWORD=
CF_SITE_KEY=
CF_SECRET_KEY=
OIDC_RP_CLIENT_ID=
OIDC_RP_CLIENT_SECRET=
To run MBT local you can use sqlite
settings_local.py
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}Then run the server
python manage.py runserverNow it should be all setup and accessable from http://localhost:8000
Update system
sudo apt update
sudo apt upgrade -yInstall postgres
sudo apt install postgresql postgresql-contrib nginx python3.11 python3.11-venv redis -yEnable and start the service
sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo systemctl enable redis
sudo systemctl start redisChange to the postgres user
sudo -i -u postgresEnter postgres
psqlCreate the user and the db
CREATE USER mybustimesdb WITH PASSWORD 'your_secure_password';
CREATE DATABASE mybustimes OWNER mybustimesdb;
\c mybustimes
GRANT ALL ON SCHEMA public TO mybustimesdb;
ALTER SCHEMA public OWNER TO mybustimesdb;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO mybustimesdb;
ALTER USER mybustimesdb CREATEDB;
\qGo back to the main user
exitTest the connection
psql -h localhost -U username -d dbnameExit if it worked
\q
Create the python venv
python3 -m venv .venvActivate the venv
source .venv/bin/activateInstall python dependencies
pip install -r requirements.txtMigrate main
python manage.py makemigrations
python manage.py migrateImport base data
python manage.py loaddata data.jsonMake your superuser
python manage.py createsuperuserCreate the service file
sudo nano /etc/systemd/system/mybustimes.serviceWeb service running on port 5681
[Unit]
Description=My Bus Times Django ASGI HTTP Workers (Gunicorn + Uvicorn)
After=network.target
[Service]
User=mybustimes
Group=mybustimes
WorkingDirectory=/srv/MyBusTimes
Environment="PATH=/srv/MyBusTimes/.venv/bin"
Environment="PYTHONUNBUFFERED=1"
ExecStart=/srv/MyBusTimes/.venv/bin/gunicorn \
mybustimes.asgi:application \
--workers 10 \
--worker-class uvicorn.workers.UvicornWorker \
--bind 127.0.0.1:5681 \
--log-level info \
--access-logfile - \
--error-logfile -
Restart=always
RestartSec=5
LimitNOFILE=4096
TimeoutStopSec=30
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.targetWebsocket running on port 5682
[Unit]
Description=My Bus Times Django ASGI WebSocket Worker
After=network.target
[Service]
User=mybustimes
Group=mybustimes
WorkingDirectory=/srv/MyBusTimes
Environment="PATH=/srv/MyBusTimes/.venv/bin"
Environment="PYTHONUNBUFFERED=1"
ExecStart=/srv/MyBusTimes/.venv/bin/uvicorn \
mybustimes.asgi:application \
--workers 1 \
--host 127.0.0.1 \
--port 5682 \
--ws websockets \
--log-level debug \
--proxy-headers
Restart=always
RestartSec=5
LimitNOFILE=4096
TimeoutStopSec=30
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.targetReload Daemon
systemctl daemon-reloadEnable and start the web service
sudo systemctl start mybustimes
sudo systemctl start mybustimes-ws
sudo systemctl enable mybustimes
sudo systemctl enable mybustimes-wsCheck if its running
sudo systemctl status mybustimesYou show now be able to access it on http://localhost:5681 No styles will be loaded yet
sudo nano /etc/nginx/sites-available/mybustimesserver {
listen 4986;
server_name mybustimes.cc www.mybustimes.cc;
client_max_body_size 1G;
# Static files
location /static/ {
alias /srv/MyBusTimes/staticfiles/;
autoindex off;
}
# Media files
location /media/ {
alias /srv/MyBusTimes/media/;
autoindex off;
}
error_page 502 /502.html;
location = /502.html {
root /usr/share/nginx/html;
internal;
}
location /message/ws/ {
proxy_pass http://127.0.0.1:5682;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
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_buffering off;
}
# Main proxy to frontend
location / {
proxy_pass http://127.0.0.1:5681;
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;
}
}Grant Nginx permitions to access mybustimes files
sudo chown -R your-user:www-data /path/to/MyBusTimes/staticfiles /path/to/MyBusTimes/media
sudo chmod -R 755 /path/to/MyBusTimes/staticfiles /path/to/MyBusTimes/media
sudo chmod +x /path/to/MyBusTimes
sudo chmod -R o+rx /path/to/MyBusTimes/staticfiles
sudo chmod -R o+rx /path/to/MyBusTimes/mediaReload Nginx
sudo ln -s /etc/nginx/sites-available/mybustimes /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginxNow it should be all setup and accessable from http://localhost