Git下载:

网站:https://code.google.com/p/msysgit/

文件:https://msysgit.googlecode.com/files/Git-1.8.4-preview20130916.exe

Apache下载:

网站:http://httpd.apache.org/

文件:http://101.36.96.118/data/4/57/b5/57b5b14df1e1dcffaf5a302c93c57b2d.zip/realuri/apache//httpd/binaries/netware/httpd_2.4.6-netware-bin.zip

·以上文件安装和配置过程就省略了,这个网络上的资料比较多的。

1.打开Apache的 httpd.conf 配置文件,修改 <Directory /> 中的 Deny from all 为 Allow from all,并在配置文件末尾添加

1 #
2 # Git Server Configured
3 #
4 Include conf/extra/httpd-git.conf

·这个配置可以避免在主要的配置文件中添加太多的内容,将我们的配置单独放在一个文件中。

2.在Apache的 conf/extra 文件夹中新建配置文件 httpd-git.conf,然后在文件中添加以下内容

复制代码
 1 # 设置Git管理库位置
 2 SetEnv GIT_PROJECT_ROOT E:/GitServer # 这里的E:/GitServer 表示Git服务的库位置
 3 SetEnv GIT_HTTP_EXPORT_ALL
 4 SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
 5 
 6 # 设置Git处理方式,其中的 ...^/git/(.*/... 部分也可以写成 ...^/(.*/...
 7 # 前者表示访问的时候使用 http://ServerName/git/Git库 的方式访问,后者使用 http://ServerName/Git库 的方式访问
 8 # 下面的 F:/Program Files/Git/libexec/git-core/git-http-backend.exe 是Git的http处理程序,在Git中有的。
 9 ScriptAliasMatch "(?x)^/git/(.*/(HEAD | info/refs |  objects/(info/[^/]+ | [0-9a-f]{2}/[0-9a-f]{38} | pack/pack-[0-9a-f]{40}.(pack|idx)) | git-(upload|receive)-pack))$" "F:/Program Files/Git/libexec/git-core/git-http-backend.exe/$1"
10 
11 # Enable mod_rewrite
12 RewriteEngine On
13 
14 # Detect git push
15 RewriteCond %{QUERY_STRING} service=git-receive-pack [OR,NC]
16 RewriteCond %{REQUEST_URI} ^/*.git/.*/git-receive-pack$ [NC]
17 RewriteRule .* - [E=AUTHREQUIRED:yes]
复制代码

 保存这个文件,将Git目录中的 bin/libiconv-2.dll 文件复制到 Git下的 libexec\git-core\ 中,这个是 git-http-backend.exe 需要用到的组件。然后(重)启动 Apache 服务器。

3.在E盘创建文件夹GitServer,并运行以下命令

1 git init --bare 项目名.git  # 生成项目库文件夹
2 cd 项目名.git
3 git update-server-info

4.现在使用 http://localhost/git/项目名.git 的路径就可以克隆项目了,然后修改文件、add、commit、push...

-- 以下为可选项:

5.配置访问权限

在Apache的conf/extra/httpd-git.conf中添加:

复制代码
1 <Location /git/> # 这个路径和上面的ScriptAliasMatch处需一致
2     AuthType Basic
3     AuthName "GIT Server"
4     AuthUserFile "E:/.htpasses" # 这个是需要验证的密码文件
5     Require valid-user # 据说如果将“Require valid-user”注释掉,就不需要密码认证了,在内网用时会很方便,但这是只允许pull,而不允许push。
6 </Location>
复制代码

然后在使用Apache的 htpasswd.exe 工具生成对应的密码文件,运行以下命令

1 htpasswd -bc E:\.htpasses 用户名 密码

如果只是要添加用户,则把 -bc 的操作改成 -b 操作即可。重启服务器,再操作该Git项目时就需要密码验证了。

6.添加Git的Web浏览工具gitphp

下载gitphp: http://www.gitphp.org 

解压到 E:\GitServer (可以是其他位置) 并将文件夹命名为 gitphp,然后在Apache的conf/extra/httpd-git.conf中添加配置

复制代码
 1 <IfModule alias_module>
 2     Alias /gitphp "E:\GitServer\gitphp"
 3 </IfModule>
 4 <Directory "E:\GitServer\gitphp">
 5     Options Indexes FollowSymLinks
 6     AllowOverride None
 7     Order allow,deny
 8     Allow from all
 9 </Directory>
10 <Location /gitphp/> #这里也是添加密码验证
11     AuthType Basic
12     AuthName "GIT Server"
13     AuthUserFile "E:/.htpasses"
14     Require valid-user
15 </Location>
复制代码

然后将其中的 config/gitphp.conf.php.example 复制新文件为 config/gitphp.conf.php,并修改其中的配置项,比如我这里修改的就是:

1 $gitphp_conf['gitbin'] = 'F:\\Progra~1\\Git\\bin\\git.exe'; // git.exe文件路径
2 $gitphp_conf['projectroot'] = 'E:\\GitServer\\'; // Git项目库位置(不是项目文件夹)

然后重新启动Apache,使用浏览器浏览 http://localhost/gitphp则就可以看到Git的Web浏览工具了。

posted on 2016-08-20 14:53  默默淡然  阅读(753)  评论(0编辑  收藏  举报