# Gitea Multi-Instance for Ubuntu 24.04 Server [![OS](https://img.shields.io/badge/ubuntu-24.04-E95420)](#) [![Shell](https://img.shields.io/badge/shell-bash-121011)](#) [![WebServer](https://img.shields.io/badge/server-nginx-009639)](#) [![DB](https://img.shields.io/badge/server-mariadb-003545)](#) [![Server](https://img.shields.io/badge/server-gitea-609926)](#) [![License](https://img.shields.io/badge/License-MIT-green)](./LICENSE) Automated Bash installer script for deploying **multiple isolated Gitea instances** on Ubuntu 24.04 Server. This is a **production-focused installer**, not a demo. It assumes Nginx and MariaDB are already installed and running. --- ## Related Installers If you don’t have the required components, you can use these compatible installers: - [Nginx Installer](https://git.x-files.dk/web-server/nginx-ubuntu) - [MariaDB Installer](https://git.x-files.dk/database-server/mariadb-ubuntu) --- > **Important** > Always complete one installation fully (including the `/etc/gitea*/gitea-postinstall` step) before running another. --- ### Download the Script Clone this repository to your server: ``` git clone https://git.x-files.dk/web-application/gitea-ubuntu-multi.git ``` ``` cd gitea-ubuntu-multi ``` ### Usage Run the script using: ``` sudo ./giteainstall -n -p [options] ``` ### Examples The installer automatically detects if socket authentication is active. Only include `-a` and `-m` if your MariaDB setup does **not** use socket authentication. ``` sudo ./giteainstall -n git.example.com -p giteadbpass sudo ./giteainstall -n git.example.com -p giteadbpass -m rootpwd sudo ./giteainstall -n git.example.com -p giteadbpass -a admin -m adminpwd ``` --- ### Options | Flag | Description | |------|--------------| | `-p ` | Gitea database user password | | `-a ` | Optional MariaDB admin username (defaults to `root` if not specified) | | `-m ` | MariaDB root or admin password — *required only if socket authentication is disabled* | | `-h`, `--help` | Show the help screen (reflects detected socket status) | --- ### Logic When you run this script: - Each Gitea instance created by this script is **fully self-contained**. - Every instance has: - Its own **Linux system user** (e.g., `gitea1`, `gitea2`, `gitea3`, …) - Its own **database** (e.g., `gitea1db`, `gitea2db`, `gitea3db`, …) - Its own **service** (e.g., `gitea1.service`, `gitea2.service`, …) - Its own **home directory** (e.g., `/home/gitea1/`, `/home/gitea2/`, …) - Its own **configuration directory** (e.g., `/etc/gitea1/`, `/etc/gitea2/`, …) - Its own **data path** (e.g., `/var/lib/gitea1/`, `/var/lib/gitea2/`, …) - A unique **HTTP port** automatically assigned during post-install All instances share the same Gitea binary (`/usr/local/bin/gitea`), so upgrading Gitea is simply replacing that binary once. | Instance | System User | Database | Config Dir | Service | Port | |-----------|--------------|-----------|-------------|----------|-------| | 1st | `gitea1` | `gitea1db` | `/etc/gitea1/` | `gitea1.service` | 3001 | | 2nd | `gitea2` | `gitea2db` | `/etc/gitea2/` | `gitea2.service` | 3002 | | 3rd | `gitea3` | `gitea3db` | `/etc/gitea3/` | `gitea3.service` | 3003 | Each instance is assigned the next available ID automatically. --- ### Customization Each instance has its own configuration and customization paths: | Type | Path | |------|------| | Configuration | `/etc/giteaX/app.ini` | | Custom assets (favicon, logo, etc.) | `/etc/giteaX/custom/public/assets/img/` | | Custom templates | `/etc/giteaX/custom/templates/` | | Data & repositories | `/var/lib/giteaX/` | --- ### Configuration Once the script finishes, open your browser and visit: ``` http:// ``` and complete the Gitea setup through the web installer form. --- ### Post-install After the web installer is done run: ```bash sudo /etc/gitea*/gitea-postinstall ``` This adjusts ports, log levels, upload limits, disables SSH access and other tweaks. > **Note** > The web installer always uses temporary port 3000. > The postinstall script automatically reconfigures each instance to its permanent port. > SSH is disabled by default after post-install (modify `/etc/gitea*/app.ini` if needed). --- ### Nginx Integration The generated Gitea configuration file listens on port 80. To enable HTTPS (port 443), use the example provided [here](https://git.x-files.dk/xtras/nginxsnippets/src/branch/main/hostfiles/gitea.443.conf). > **IMPORTANT** > If you enable HTTPS, update `/etc/giteaX/app.ini` (`ROOT_URL` setting) > from `http` to `https`, then restart both Nginx and Gitea. > **NOTE** > The file also includes optional caching directives (commented out by default). > You can enable them to improve load times and performance if needed. > The lines you are looking for are at the bottom of the generated config file and look like this: > ``` > ##### Cache js css static content and open files start ##################### > # include /etc/nginx/nginxsnippets/cache-open-files.conf; > # include /etc/nginx/nginxsnippets/cache-statics.conf; > # include /etc/nginx/nginxsnippets/cache-js-css.conf; > ##### Cache js css static content and open files stop ###################### > ``` --- ### Version Handling This installer automatically checks the latest **Gitea version** from [https://dl.gitea.com/gitea/version.json](https://dl.gitea.com/gitea/version.json) If it fails, it falls back to the version number stored in the **`fallback`** file. That file contains one line, for example: ``` 1.24.6 ``` > **Why a separate file?** > Keeping the fallback version outside the script avoids polluting the code with constants. > This keeps updates clean and ensures the installer logic never changes just because a version bump is needed. --- ### Troubleshooting **Nginx fails to restart** Run `nginx -t` and review any syntax errors reported in `/etc/nginx/conf.d/.conf`. **Gitea front-end not loading** Run `systemctl status gitea nginx` and ensure both Gitea and Nginx services are active. **Access denied during database creation** Your MariaDB setup likely does not use socket authentication. Re-run the installer with the `-m` flag (and optionally `-a`) to provide credentials. --- ### FAQ **Q:** Why doesn’t the script ask for a MariaDB password by default? **A:** Ubuntu 24.04’s MariaDB installation defaults to *socket authentication*, allowing the local `root` user to connect without a password. The installer detects this automatically and skips password prompts when applicable. **Q:** Can I run the installer multiple times? **A:** Yes. Database and user creation use `IF NOT EXISTS`, making them safe to re-run. Existing configuration files are replaced, but no data is deleted. **Q:** Does this modify existing Nginx settings? **A:** No. It adds a standalone host file in `/etc/nginx/conf.d/` and validates configuration changes before applying them. --- ### More Information More guides and documentation can be found on [wiki.x-files.dk](https://wiki.x-files.dk) --- ### License Licensed under the [MIT License](./LICENSE)