`
huobengluantiao8
  • 浏览: 1077261 次
文章分类
社区版块
存档分类
最新评论

Apache 搭建git 服务器

 
阅读更多

原文地址:http://www.jeremyskinner.co.uk/2010/07/31/hosting-a-git-server-under-apache-on-windows/


Last month I posted abouthosting a git server under IISby usingGitAspx. While this is certainly one way to host a git server on windows, I wouldn’t recommend this in a production environment.

An alternative (and somewhat more stable) approach is to use the native implementation of git-http-backend that ships withmsysgitalong with Apache.


Step 1: Install Git

Firstly you’ll need to installmsysgit. The current stable version is 1.7.0.2, but this process should also work with the 1.7.1 beta. Be sure to selectRun git from the Windows Command promptwhen the installer asks you if you want to modify your PATH variable.

Once installed, you’ll need to tweak the installation slightly. By default, the git http server is located at C:Program Files (x86)Gitlibexecgit-coregit-http-backend.exe(on x64 systems). If you try and run git-http-backend.exe you’ll get the message that the application couldn’t be started because libiconv2.dll is missing:

image

In order to fix this, copy libiconv2.dll fromC:Program Files (x86)GitbintoC:Program Files (x86)Gitlibexecgit-core

Now when you run git-http-backend.exe from a command prompt, the application should run and you should see an HTTP 500 server error:

image

Step 2: Install Apache

Next you’ll need to install the Apache webserver. I’m using the 2.2.16 installerwhich can be found here. I ran through the installation using the default options so my Apache instance is running on port 80.

If you visit http://localhost at this point you should be greeted with Apache’s standard “It works!” message.

Step 3: Create Repositories Directory

Create the directory where you want to store your git repositores. I’m usingC:Repositories.For testing purposes I created an empty test repository:

image

You’ll also need to put some content in this test repositor

Step 4: Modify Apache Configuration

Next, you’ll need to modify the Apache configuration file so that it forwards requests to git-http-backend.exe. This is done by editinghttpd.confinC:Program Files (x86)Apache Software FoundationApache2.2conf

At the bottom of httpd.conf, add the following lines:

SetEnv GIT_PROJECT_ROOT C:/Repositories
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAliasMatch \
        "(?x)^/(.*/(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))$" \
       "C:/Program Files (x86)/git/libexec/git-core/git-http-backend.exe/$1"



The first line tells git where your repositories are located. The second line tells git that all repositories in this directory should be published over http (by default, git will only publish those repositories that contain a file named “git-daemon-export-ok”). The final lines tell apache to route git-specific URLs to the git http server.

Finally, if you want to be able to clone from the server without authentication, then you’ll need to tell Apache to allow anonymous access by adding the following lines into httpd.conf:

<Directory />
  Allow from all
</Directory>

After saving the changes, restart the Apache service.

Step 5: Clone the test repository

Next, clone the test repository that you crated in step 3 by issuing the commandgit clone http://localhost/Test.git

If all goes well, you should see the following output:

image

At this point, you can now clone repositories from the server without any authentication.

Step 6: Authentication

If you try to push changes to the repository you cloned in step 5, you’ll receive an error:

image


This is because by default, you can only pull from repositories anonymously, while pushing requires authentication to be enabled.

Scenario 1: Allow anonymous pushes

Sometimes you may want to allow users to push to your repositories without authentication, for example when using an internal, privately hosted server.

To enable this scenario, edit theconfigfile in C:RepositoriesTest.git on the server and add the following lines to the bottom of the file:

[http]
  receivepack = true

This will allow git to accept pushes from anonymous users.

Note that you’ll have to add this to every repository that you create. I’ll show a nicer way to do this later in the tutorial.

Scenario 2: Anonymous pull, authenticated push

This is the default scenario. Git will only allow users to push if they have been authenticated with apache.

There are several ways to enable user accounts with apache. The most basic is to use .htaccess files, although you can also configure integration with Windows user accounts and Active Directory by using mod_authnz_ldap. Configuring these is outside the scope for this tutorial, but there are plenty of examples on the internets.

Once authentication is set up, you’ll need to ensure that you clone your repositories with the username in the URL, as git will not prompt you for a username by default:

git clone http://MyUserName@mygitserver/Test.git

Git will then prompt you for a password every time that you try to push. You can also hard code the password in the URL (somewhat insecure) if you want to avoid this prompt:

git clone http://MyUserName:Password@mygitserver/Test.git

To make this more secure, you could enable SSL on the server and require authenticated traffic to go over HTTPS. Although configuring OpenSSL with apache is outside the scope for this tutorial, I will point out that once configured, you will need to disable the SSL verification on your git client by running:

git config --global http.sslverify false

If you don’t do this, you’ll get an error saying“error setting certificate verify locations”every time you try to clone/push/pull over HTTPS.

Step 7: A prettier UI

At this point, you should be able to clone, pull from and push to the server. However, creating new repositories requires that you connect remotely to the server and run git init from a command prompt on the server.

A nicer alternative is to use a web-based front for the creation of repositories. For this I’ll be usingGitPhpHomepagewhich is a small collection of PHP scripts that I ported fromGitAspx'sASP.NET-based UI to PHP in order to get it working under Apache.

First, you’ll need to install PHP on the server. I’ll be using the PHP 5.3.3 Windows binaries that can be found athttp://windows.php.net/download/. The download page is somewhat confusing, offering both thread-safe and non-thread-safe versions compiled with both VC6 and VC9. For use with Apache 2.2 be sure to select theVC6 x86 Thread Safe zip package. Here’sa direct link.

Unzip the contents of this package toC:PHPon the server and add this directory to Windows’ PATH environment variable:

image

Next, rename the php.ini-production file to just php.ini and edit the following settings:

Uncomment and edit the “extension_dir” (about half way through the file) so that it says the following:

extension_dir = "c:phpext"

Next, edit your Apache configuration file (C:Program Files (x86)Apache Software FoundationApache2.2confhttpd.conf) and add the following lines to the bottom of the file:

AddType application/x-httpd-php .php
LoadModule php5_module "C:/php/php5apache2_2.dll"
PHPIniDir "C:/php"

This tells Apache to map .php file extensions to the PHP5 apache module located in C:php.

You’ll also need to tell Apache to look for index.php as a default index file. This can be done by searching for the lines that look like this:

<IfModule dir_module>
  DirectoryIndex index.html
</IfModule>

…and changing them to this:

<IfModule dir_module>
  DirectoryIndex index.php index.html
</IfModule>

Be sure to restart the Apache server once you’ve made these changes.

To see whether this is working, create a file called phpinfo.php in C:Program Files (x86)Apache Software FoundationApache2.2htdocs and place in it the following content:

<?php phpinfo(); ?>

Now, visiting http://mygitserver/phpinfo.php should display a page containing PHP configuration information.

Now that PHP is configured, download the GitPhpHomepage files fromhttp://github.com/JeremySkinner/GitPhpHomepageand unzip them into C:Program Files (x86)Apache Software FoundationApache2.2htdocs

Be sure to edit the config.php file so that it accurately reflects both the git installation directory and your repositories directory.

At this point, visiting http://mygitserver should display a page where you can view and create repositories:

image

Pressing the “Create a new bare repository” button will open a dialog where you can create a new repository, including the option to enable anonymous pushes:

image


Obviously, if you’re thinking of using this on a public-facing server you should enable authentication so that not just anyone can create repositories on your server.
分享到:
评论

相关推荐

    Linux下使用Apache搭建Git服务器

    近在学Linux,终于在Linux上用Apache搭建起了Git服务器,在此记录一下。  服务器:阿里云服务器  Linux版本:CentOS 6.5  Apache版本:Apache/2.2.15  Git版本:git 1.7.1  Git访问方式:基于http的基本...

    在公司搭建自己的git服务器.zip

    下面我们将详细探讨如何在公司内部搭建git服务器,并通过提供的文档和资源来深入理解git的相关知识。 首先,我们需要了解git的基本概念。Git是一款分布式版本控制系统,由Linux之父Linus Torvalds开发,用于管理...

    搭建git服务器方法

    ### 搭建Git服务器方法详解 随着版本控制系统在软件开发中的广泛应用,Git因其高效、灵活的特点成为首选工具之一。本文旨在为初学者提供一份全面的指南,介绍如何在CentOS 6.5环境下搭建一个基于HTTP基本认证的Git...

    git基础(git服务器搭建+git教程+git廖雪峰)

    ### Git服务器搭建 1. **安装Git服务器**:在服务器上安装Git,通常使用`sudo apt-get install git`(Ubuntu/Debian)或`yum install git`(CentOS/RHEL)。 2. **初始化仓库**:在服务器上选择合适的位置创建空仓库...

    搭建(基于http协议)git服务器的安装配置说明.docx编程资料

    ### 搭建基于HTTP协议的Git服务器安装配置说明 #### 一、软件运行环境 在开始之前,确保你的服务器满足以下配置: - **服务器版本**:CentOS 5.10 (Final) - **Apache版本**:Apache-2.2.3 - **Git版本**:git-...

    搭建(基于http协议)git服务器的安装配置说明.docx

    搭建基于HTTP协议的Git服务器是将Git仓库与Web服务器相结合,允许用户通过HTTP协议来克隆、推送和拉取代码。在这个过程中,我们将使用Apache作为Web服务器,Git作为版本控制系统,Gitweb作为Web接口,而身份验证则...

    tomcat搭建git私服

    ### 基于WebDAV在Tomcat中搭建Git私有服务器 在现代软件开发过程中,版本控制系统(Version Control System, VCS)是必不可少的一部分,其中Git作为最流行的分布式版本控制工具之一,被广泛应用于各类项目中。对于...

    2021-2022年精品资料搭建基于http协议git服务器的安装配置说明.docx

    搭建基于HTTP协议的Git服务器是将Git仓库托管在服务器上并允许通过HTTP协议进行操作的过程。这个过程在很多情况下适用于不支持SSH协议或者为了安全性和管理便利性而选择HTTP方式的场景。以下是对该文档中描述的步骤...

    简单搭建WEB服务器 简单搭建WEB服务器 简单搭建WEB服务器

    本文将详细介绍如何简单搭建一个WEB服务器,包括基础概念、所需工具及步骤,旨在帮助初学者快速入门。 一、Web服务器的基础概念 1. HTTP:HTTP是互联网上应用最为广泛的一种网络协议,用于从万维网服务器传输超文本...

    git服务哭搭建

    本教程将详述如何在Ubuntu系统上搭建Git服务器,包括安装与配置多个组件,如X11VNC远程管理、OpenSSH服务器、Git守护进程(Git Daemon)、Gitweb以及Java。 首先,我们需要【安装Ubuntu系统】,这是一个基于Debian...

    windows 搭建本地svn服务器

    要搭建Windows上的本地SVN服务器,我们主要会使用Apache HTTP Server作为Web服务器,并安装Subversion作为后端服务。以下是详细步骤: 1. **安装Subversion**: 首先,我们需要下载并安装Subversion。提供的文件...

    搭建电影服务器

    搭建电影服务器是一个涉及多个IT领域的综合任务,包括网络服务、流媒体技术、服务器配置和安全性管理等。以下是一份详细的步骤指南,旨在帮助你轻松掌握如何建立一个电影服务器。 一、选择服务器硬件与操作系统 ...

    git服务搭建全过程

    #### 一、对外GIT服务器搭建 对外GIT服务器的搭建主要涉及以下步骤: 1. **选择并配置Git与Gerrit**: - **Git与Gerrit版本**: 选用Git结合Gerrit 2.16.7进行配置。 - **访问地址**: 通过`...

    虚拟机ubuntu14.04配置git及gitweb服务器.docx

    3. **搭建Git服务器** 首先,确保已安装`open-ssh-server`和`openssh-client`。然后,切换到超级用户,使用`ssh-keygen -t rsa`生成SSH密钥对,存储在`~/.ssh`目录下。无需为密钥设置密码,只需一路回车即可。这样...

    Apache本地服务器软件

    在本地环境中搭建Apache服务器,用户可以即时预览网页改动,极大地提高了工作效率。Apache服务器支持多种操作系统,包括Windows、Linux和Mac OS等,这使得它成为跨平台开发的理想工具。此外,它兼容各种编程语言,如...

    【内网Git-Server(基于smart http方式)部署】.pdf

    本文主要介绍在内网环境...通过这些步骤,可以成功搭建一个支持基本HTTP验证的内网Git服务器,为公司内部的开发人员提供代码托管服务。注意在实际操作中,所有的配置文件修改都需要谨慎处理,以确保系统的安全与稳定。

    git 学习资料大全,pro git 资料 gitweb资料实战

    在 Git 实战中,了解如何在服务器上搭建 Git 服务是非常重要的一步。这通常包括以下步骤: 1. 安装 Git:在服务器上安装 Git 环境,确保所有必要的依赖都已就绪。 2. 配置 Git 用户:创建一个专门用于 Git 服务的...

    在VMware+centOS 8上基于http协议搭建Git服务的方法

    在本文中,我们将详细介绍如何在VMware上的CentOS 8操作系统中通过HTTP协议搭建Git服务。这个过程对于希望从Android设备访问虚拟机中的Git服务尤为有用。以下是搭建步骤的详细说明: 1. **起因**: 实现Android...

    持续集成环境搭建——maven、git、jenkins、tomcat

    接下来,我们可以使用git进行版本控制,jenkins进行持续集成,而tomcat作为应用服务器部署我们的Web应用程序。这个集成环境有助于团队高效协作,确保代码质量和稳定性。在实际工作中,根据项目需求,可能还需要配置...

    ASP本地环境搭建工具

    1. **Web服务器组件**:在没有IIS的情况下,我们可以使用其他支持ASP的Web服务器,比如WAMP(Windows, Apache, MySQL, PHP)或者XAMPP(cross-platform, Apache, MySQL, PHP, Perl),尽管它们主要设计为PHP的开发...

Global site tag (gtag.js) - Google Analytics