blog/content/post/install-and-use-gitea.md
2023-02-12 11:45:36 +05:30

3.7 KiB

title date lastmod draft keywords description tags categories author comment toc autoCollapseToc postMetaInFooter hiddenFromHomePage contentCopyright reward mathjax mathjaxEnableSingleDollar mathjaxEnableAutoNumber hideHeaderAndFooter flowchartDiagrams sequenceDiagrams
Install and Use Gitea 2023-02-12T11:11:29+05:30 2023-02-12T11:11:29+05:30 false
gitea git repository repo
gitea git
linux server
false true false true false false false false false false false
enable options
false
enable options
false

Here I document my steps to get Gitea up and running on a Debian server.

Gitea is a self-hosted service to host and accept contributions to your git repositories on the web.

Prerequisites

  • git
  • curl/wget to obtain the binary
  • MySQL/PostgreSQL/MSSQL/SQLite3/TiDB

Getting Gitea

Go to Gitea's official website for installation instructions.

It usually boils down to

  1. Obtaining and verifying the binary
  2. Creating a user
  3. Creating directory structure
  4. Creating a service file
  5. Setting up a databse
  6. Configuring Gitea

Create user

Create a user to run Gitea. Here we name it 'gitea' for the sake of our convenience.

adduer \
--system \
--shell /bin/bash \
--gecos 'Gitea' \
--group \
--disabled-password \
--home /home/gitea \
gitea

Create directory structure

mkdir -p /var/lib/gitea/{custom,data.log}
chown -R gitea:gitea /var/lib/gitea
chmod -R 750 /var/lib/gitea
mkdir /etc/gitea
chown root:gitea /etc/gitea
chmod 770 /etc/gitea

Copy Gitea binary to global location

cp gitea /usr/local/bin/gitea

Create a service file

Copy the sample gitea.service to /etc/systemd/system/gitea.service, then edit the file with a text editor.

Replace the lines starting with --- to +++.

--- #Wants=postgresql.service
--- #After=postgresql.service
+++ Wants=postgresql.service
+++ After=postgresql.service

--- User=git
--- Group=git
+++ User=gitea
+++ Group=gitea 

Set up a database

As user postgres, run the following

createuser gitea
createdb gitea
psql
alter user gites with encrypted password 'super-secure-password';
grant all privileges on database gitea to gitea;
\q

Set up a web server

Put the following configuration in /etc/caddy/Caddyfile

gitea.adityakumar.com {
  reverse_proxy localhost:3000

}

Now reload caddy

systemctl reload caddy 

Configure Gitea

Enable and start Gitea

systemctl enable --now gitea.service 

Head to the website, or go to localhost:3000 if you have physical access to the server. Alternatively you can use port forwarding to configure Gitea using your local machine.

On the page,

  • enter database username, password and database name.
  • change Site Title to whatever you prefer.
  • enter gitea in Run As Username field.
  • change Gitea Base URL to the site's URL

Rest of the options should be left as is unless you have other requirements.

Click on Install Gitea. It should write the configuration to /etc/gitea/app.ini and ready for use.

Now change permissions on /etc/gitea to make it read-only.

chmod 750 /etc/gitea
chmod 640 /etc/gitea/app.ini