Gitlab similar to GitHub, the library created with GitHub must be a public library, which is difficult for some privacy files, so you can use Gitlab to build your own private github.
This article is mainly about how to use the Web-hooks provided by Gitlab to realize the automatic updating of the repository to the remote repository;
1. First you need to install the lamp or LNMP environment in a remote git repository server (this is where you install lamp directly with Yum);
Yum install-y httpd mysql mysql-libs php php-mysql mysql-server php-bcmath php-gd php-mbstring
2. Write a user-triggered script
Cat/var/www/html/update.php<?php//git Warehouse Directory $www_folder = "/home/apache/baby";//Execute command echo shell_exec ("CD $www _ Folder && git pull 2>&1 ");? >
3. Place the update.php in the Apache web directory so that it can be accessed by the browser;
because executing the update.php script requires the permission of the Apache startup user, the following actions are used by Apache users;
4. Create key (login Apache user)
Apache user country is created automatically when Yum installs httpd, so the default is no login permission and home directory, need to change to the following:
grep ' Apache '/etc/passwd apache:x:48:48:apache:/home/apache:/bin/bash
#修改好后, login Apachesu apache# Create a secret key ssh-keygen-t rsa-c "[email protected]" #把apache用户目录下的. Ssh/id_rsa.pub content to SSH to Gitlab users Keys,
Copy the. Ssh/id_rsa.pub content from the Apache user directory to the SSH Keys in the Gitlab user,
5. Clone a user's repository to a local
git clone [email protected]:username/baby#gitlab.com:gitlab domain name (access link) #username: The name of the repository #baby:gitlab the user name
6. Testing
You can now submit a merge request using another user, and then the master user accepts the merge
Then login to Apache server to see if there is automatic synchronization;
This method is only triggered when merging other branches into master Master branch;
This article from the "Shallow faint" blog, reproduced please contact the author!
Gitlat Web Hooks App