Skip to content

🌐 Gitea¢

☁️ Cloudflare Setup¢

  1. βœ… Verify Cloudflare DNS
    Ensure your domain is pointed to Cloudflare's DNS.
    Cloudflare DNS Setup

  2. πŸ”’ Access Cloudflare Zero Trust
    Go to Cloudflare Zero Trust.

  3. πŸ” Navigate to Network > Tunnels.

  4. πŸ› οΈ Create a Tunnel
    Select the Debian 64-bit architecture.

  5. πŸ’» Install Cloudflared on Ubuntu 24.04
    Copy the Cloudflared connector and install it on your server.

  6. 🏷️ Configure the Public Hostname
    Public Hostname Configuration


πŸ–₯️ Step 1: Update Your SystemΒΆ

Start by updating your system packages:

sudo apt-get update
sudo apt-get upgrade

πŸ—„οΈ Step 2: Install and Configure MariaDBΒΆ

πŸ“¦ Install MariaDBΒΆ

Run the following commands to install MariaDB:

sudo apt install -y mariadb-server
sudo mysql_secure_installation

Follow the prompts:

  • Current root password: Press Enter
  • Switch to unix_socket authentication: n
  • Change root password: Press Enter or type Y and set a new password.
  • Remove anonymous users: Press Enter or type Y
  • Disallow root login remotely: Press Enter or type Y
  • Remove test database: Press Enter or type Y
  • Reload privilege tables: Press Enter or type Y

πŸ—ƒοΈ Create the Gitea DatabaseΒΆ

Open the MariaDB prompt:

sudo mariadb

Create the Gitea database and user:

CREATE DATABASE gitea;
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY 'Strong-Password';
FLUSH PRIVILEGES;
EXIT;

πŸš€ Step 3: Install GiteaΒΆ

πŸ‘€ Create a User for GiteaΒΆ

Create a system user named git:

sudo adduser --system --shell /bin/bash --group --disabled-password --home /home/git git

πŸ“₯ Download and Move GiteaΒΆ

Download Gitea and move it to the /usr/bin directory:

wget https://dl.gitea.com/gitea/1.22.3/gitea-1.22.3-linux-amd64
sudo mv gitea-1.22.3-linux-amd64 /usr/bin/gitea

πŸ”’ Set PermissionsΒΆ

Adjust the permissions for the Gitea binary:

sudo chmod 755 /usr/bin/gitea

πŸ“‚ Create Required DirectoriesΒΆ

Set up the necessary directories for Gitea:

sudo mkdir -p /etc/gitea /var/lib/gitea/{custom,data,indexers,public,log}
sudo chown git:git /etc/gitea /var/lib/gitea/{custom,data,indexers,public,log}
sudo chmod 750 /var/lib/gitea/{data,indexers,log}
sudo chmod 770 /etc/gitea

βš™οΈ Create the Gitea Service FileΒΆ

Create a new service file for Gitea:

sudo nano /etc/systemd/system/gitea.service

Add the following content:

[Unit]
Description=Gitea
After=syslog.target
After=network.target

[Service]
RestartSec=3s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

[Install]
WantedBy=multi-user.target

Save and exit the file (Ctrl + O, Enter, Ctrl + X).

πŸ”„ Start the Gitea ServiceΒΆ

Reload the systemd daemon and start the Gitea service:

sudo systemctl daemon-reload
sudo systemctl start gitea

Enable Gitea to start on boot:

sudo systemctl enable gitea

🌍 Step 4: Access Gitea Web Interface¢

Open your web browser and go to http://<IP-address-of-your-server>:3000. You will see Gitea's initial configuration screen.

To use Gitea with a domain, set up a reverse proxy using your preferred web server (Nginx, Apache, etc.). This will allow access to Gitea without specifying a port.

During the initial setup, use the database credentials created earlier and configure the general settings. Click β€˜Install Gitea’ to complete the setup, and you will be redirected to the Gitea homepage where you can log in.

πŸ“ Step 5: Modify the INI FileΒΆ

If you use Cloudflare to create a (sub)domain for your Gitea instance, it’s essential to modify the INI file to restrict user sign-ups.

Locate the file at /etc/gitea/app.ini and make the necessary adjustments.

Restart the Gitea service:

sudo systemctl restart gitea