Windows使用Apache2配置Git服务器

Windows使用Apache2配置Git服务器php

本文地址:http://www.cnblogs.com/cnscoo/p/3373095.htmlhtml

Git下载:git

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

文件: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.zipide

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

1.打开Apache的 httpd.conf 配置文件,修改 <Directory /> 中的 Deny from allAllow 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浏览工具了。

很晚了,打完收工。今晚又被公司加班了,此夜绵绵无绝期啊...

相关文章
相关标签/搜索