1. Configure the environment required by Gogs
sudo apt-get install nginx
sudo apt-get install git
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/
sudo chmod +x /etc/init.d/gogs
cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/
sudo service gogs start
3. Browser configuration gogs
http://*******: 3000/install - replace the asterisk part with the ip address
4.nginx reverse proxy
- Create the corresponding profile
sudo vim /etc/nginx/sites-enabled/gogs.conf
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.