Build your own git server with Gogs

Posted by yonta on Thu, 05 Dec 2019 01:50:22 +0100

1. Configure the environment required by Gogs

  • Install nginx
sudo apt-get install nginx
  • Install git
sudo apt-get install git
  • Install MySQL
sudo apt-get install mysql-server # Install mysql
mysql -u root -p # Connect to database
SET GLOBAL storage_engine = 'InnoDB';  # Set the database mode to InnoDB
CREATE DATABASE gogs CHARACTER SET utf8 COLLATE utf8_bin; # Create database named gogs
GRANT ALL PRIVILEGES ON gogs.* TO 'root'@'localhost' IDENTIFIED BY 'YourPassword'; # Assign permissions to database gogs
FLUSH PRIVILEGES;  # Refresh
QUIT; # Sign out
  • Create a separate user for Gogs
sudo adduser git  # Create user git
su git # Switch to git user
cd ~  # Switch to home directory
wget https://Dl.gogs.io/0.11.4/linux? Amd64.zip? Download gogs
unzip linux_amd64.zip # decompression

2. Configure and run Gogs

  • Modify the Gogs service configuration file
vim /home/git/gogs/scripts/init/centos/gogs
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Go Git Service"
NAME=gogs
SERVICEVERBOSE=yes
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
WORKINGDIR=/home/git/gogs #This is modified according to its own directory
DAEMON=$WORKINGDIR/$NAME
DAEMON_ARGS="web"
USER=git  #If you are not using this user to run gogs, modify the corresponding user
  • Switch to root account and copy to / etc/init.d/
sudo cp /home/git/gogs/scripts/init/centos/gogs /etc/init.d/
  • Add execution permission
sudo chmod +x /etc/init.d/gogs
  • Copy service
cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/
  • Start Gogs
sudo service gogs start

3. Browser configuration gogs

  • Open browser 3000 port
http://*******: 3000/install - replace the asterisk part with the ip address
  • Configure gogs. Related information: gogs configuration manual
  • Gogs configuration file: / home/git/gogs/custom/conf/app.ini

4.nginx reverse proxy

  • Create the corresponding profile
sudo vim /etc/nginx/sites-enabled/gogs.conf
  • Add to
server {
        listen 80;
        server_name  code.chinahufei.com;
        location / {
                proxy_pass http://127.0.0.1:3000/;
        }
}
  • In this way, you can register to create an account and log in.

Topics: Programming git sudo Database Nginx