偷瓜的贼 发表于 2015-3-10 12:19:02

在Linux上用Apache搭建Git服务器

  最近在学Linux,终于在Linux上用Apache搭建起了Git服务器,在此记录一下。
  服务器:阿里云服务器
  Linux版本:CentOS 6.5
  Apache版本:Apache/2.2.15
  Git版本:git 1.7.1
  Git访问方式:基于http的基本验证(非SSL)
  Apache的安装
  1. 安装Apache软件:yum install httpd
  2. 设置Apache在服务器启动时运行:chkconfig --levels 235 httpd on
  Git的安装与配置
  1. 安装git



yum install git
  2. 安装 git-core(为了使用git-http-backend——支持git的CGI程序,apache支持git就靠它)



yum install git-core
  3. 创建存放git repository的文件夹,比如这里是/home/git



cd /home && mkdir git && cd git
  4. 创建一个空的项目



mkdir git-test && cd git-test
  5. 修改上一步创建的文件夹git-test的所有者与所属群组,要让apache能读/写这个文件夹



chown -R apache:apache .
  chown命令使用帮助:每天一个linux命令(30): chown命令
  Apache的配置
  1. 创建用于git用户验证的帐户(用户帐户由apache管理)
  1.1 创建新用户



htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd
  然后输入该用户要使用的密码。
  1.2 修改git-team.htpasswd文件的所有者与所属群组



chown apache:apache /etc/httpd/conf.d/git-team.htpasswd
  1.3 设置git-team.htpasswd文件的访问权限



chmod 640 /etc/httpd/conf.d/git-team.htpasswd
  chmod命令使用帮助:每天一个linux命令(27):linux chmod命令
  2. 修改apache配置文件httpd.conf
  2.1 用vim打开httpd.conf:vi /etc/httpd/conf/httpd.conf
  2.2 将光标移至文件结尾:0G
  2.3 添加如下的内容:




ServerName git.iyunv.com
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv GIT_PROJECT_ROOT /home/git
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/

AuthType Basic
AuthName "Git"
AuthUserFile /etc/httpd/conf.d/git-team.htpasswd
Require valid-user


  ServerName是git服务器的域名
  /home/git是代码库存放的文件夹
  ScriptAlias是将以/git/开头的访问路径映射至git的CGI程序git-http-backend
  AuthUserFile是验证用户帐户的文件
  2.4 保存并退出:x
  3. 重启apache使设置生效



service httpd restart
  客户端访问Git服务器
  运行以下命令签出git-test项目:



git clone http://git.iyunv.com/git/git-test
  输入用户名与密码,如果输出下面的信息,就说明签出成功。



remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
  
  参考资料:
  Git server setup on linux using smart HTTP
  Git: HTTPS Repository + Access Control
  Setting up an SSL secured Webserver with CentOS
页: [1]
查看完整版本: 在Linux上用Apache搭建Git服务器