-
Notifications
You must be signed in to change notification settings - Fork 0
Manual setup for Linux‐API
This guide provides step-by-step commands and concise explanations for installing and running Linux-API on an Ubuntu server. The project was developed and tested on an Ubuntu 25 system; the steps should work on other recent Ubuntu releases as well.
- A machine running Ubuntu with a user that has
sudoprivileges. - Internet access to download packages and container images.
Update package lists and upgrade installed packages:
sudo apt update
sudo apt upgrade -yInstall required packages (Python tooling, git, curl, GPG, and PostgreSQL client/dev files):
sudo apt install -y python3-venv python3-pip git ca-certificates curl gnupg libpq-dev postgresql-clientCreate a directory for apt keyrings, download Docker's GPG key, and add the Docker repository:
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullCreate the directory for the PostgreSQL key, download the key, and add the repository:
sudo install -d /usr/share/postgresql-common/pgdg
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.gpg
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.listRefresh package lists to include the new repositories:
sudo apt updateInstall Docker and the PostgreSQL client (example: v18):
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin postgresql-client-18Test Docker with a simple container:
sudo docker run hello-worldOptional: allow your user to run Docker without sudo:
sudo usermod -aG docker $USER
newgrp dockerNote: logging out and back in also applies the group change.
Clone the repository and enter the project directory:
git clone https://github.com/Ivole32/Linux-API
cd Linux-APICreate and activate a Python virtual environment, then install Python dependencies:
python3 -m venv venv
source ./venv/bin/activate
pip install -r requirements.txtCreate the environment file from the example and generate a secure API Secret for password hashing:
cp example.env .env
openssl rand -hex 32Open .env in your preferred editor and set API_KEY_SECRET to the generated value. Fill in other variables (database credentials, hostnames, etc.) according to example.env. Keep .env secret.
Update a couple of paths in ./api/config/config.py so the application can find them reliably. From the repository root, you can set NEW_BASE to the project root and run the replacements:
NEW_BASE="$(pwd)"
sed -i "s|DATABASE_BACKUP_DIR = .*|DATABASE_BACKUP_DIR = r\"$NEW_BASE/backup\"|" ./api/config/config.py
sed -i "s|ALEMBIC_INI_FILE = .*|ALEMBIC_INI_FILE = r\"$NEW_BASE/alembic.ini\"|" ./api/config/config.pyThe first command sets the backup directory used by the app; the second points Alembic to the correct ini file.
After editing those options, verify application-specific settings in api/config/config.py and update values there if needed. Documentation about what those options mean is here.
Start the database and related containers using the docker compose definitions. From the repository root:
cd docker
docker compose --env-file ../.env up -d
cd ..If services fail to start immediately, re-run the docker compose command once more. Verify containers are running with docker ps — you should see entries such as linux_api-postgres and linux_api-pgpool.
Run the application using Uvicorn:
python3 -m uvicorn api.server:app --host 0.0.0.0 --port 8080 --log-level debugOr use ./start.sh
If the server reports user creation errors at startup, stop and restart the server.
- Issues: https://github.com/Ivole32/Linux-API/issues
- Support the project: https://ko-fi.com/ivole32
Made with ❤️ by Ivole32 — https://github.com/Ivole32