# How to install git server on ubuntu
## install git
sudo apt-get install git
## add git user
sudo useradd git
sudo passwd git
## install postgres
sudo apt-get install postgresql
sudo apt-get install pgadmin3
pgadmin3 is optional, its a gui administration tool for PostgreSQL
### create database
~$ sudo -i -u postgres
~$ psql
## if there have a error
## psql could not connect to server : No sunch file or directory
## please retart service postgresql
## Command : sudo /etc/init,d/postgresql restart
postgres=# CREATE USER git WITH PASSWORD 'myPassword';
Add a database called gogs
postgres=# CREATE DATABASE gogs;
Now grant all privileges on database
postgres=# GRANT ALL PRIVILEGES ON DATABASE gogs to git;
Type \q to quit:
postgres=# \q
try to connect new database with git user
~$psql -U git gogs
##if get error
##"psql: FATAL: Peer authentication failed for user "git""
## sudo vi /etc/postgresql/9.5/main/pg_hba.conf
## change
## local all all peer
## to
## local all all md5
##
## sudo service postgreql restart
## install gogs server
sudo -i -u git
download gogs package from https://dl.gogs.io
extract downloaded package
cd gogs
sudo chown -R git:git /home/git/gogs
config custom/conf/app.ini follow this link https://gogs.io/docs/advanced/configuration_cheat_sheet
* database config
* repository path
* server config
* mailer config
### config example
```
[database]
DB_TYPE = postgres
HOST = 127.0.0.1:5432
NAME = gogs
USER = git
PASSWD = myPassword
SSL_MODE = require
PATH = data/gogs.db
[repository]
ROOT = /home/git/gogs-repositories
[server]
DOMAIN = 192.168.1.100
HTTP_PORT = 3000
ROOT_URL = http://192.168.1.100:3000/
DISABLE_SSH = false
SSH_PORT = 22
OFFLINE_MODE = false
[mailer]
ENABLED = True
DISABLE_HELO = true
HELO_HOSTNAME = hello
HOST = smtp.exmail.qq.com:25
FROM = user@email.com
USER = user@email.com
PASSWD = passwd
SKIP_VERIFY = true
[service]
REGISTER_EMAIL_CONFIRM = false
ENABLE_NOTIFY_MAIL = true
DISABLE_REGISTRATION = false
ENABLE_CAPTCHA = true
REQUIRE_SIGNIN_VIEW = false
```
### start run gogs
./gogs web
## supervisor
supervisor used to auto restart gogs server when fail
sudo apt-get install supervisor
add config file: vim /etc/supervisor/conf.d/gogs.conf
```
[program:gogs]
directory=/home/git/gogs/
command=/home/git/gogs/gogs web
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/gogs/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/log/gogs/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
user = git
environment = HOME="/home/git", USER="git"
```
sudo touch /var/run/supervisor.sock
sudo chmod 777 /var/run/supervisor.sock
sudo mkdir /var/log/gogs
sudo touch /var/log/gogs/stdout.log /var/log/gogs/stderr.log
sudo chmod 777 /var/log/gogs/*
sudo supervisorctl restart
sudo reboot
run supervisorctl to check if gogs is running
## log
check the log file if gogs server fail, the log in:
/home/git/gogs/log/gogs.log
/var/log/gogs/stderr.log
/var/log/gogs/stdout.log
# BACKUP
## TODO repo backup
## TODO database backup