This how-to describes setting up a Git http-backend on a Windows server with XAMPP.
Prerequisites
- Having set up the XAMPP package (see www.apachefriends.org)
- Having set up Git on Windows (see http://git-scm.com)
- Basic Git knowledge
- Starting and stopping the Apache webserver
All code examples below starting with $ ...
have to be executed in the Git Bash shell.
Setting up a repository on the server
On the XAMPP server, the webroot by default is in C:\xampp\htdocs
.
Create a new directory for git repositories below the webroot:
$ cd /c/xampp/htdocs $ mkdir git $ cd git $ git --bare init new-repo.git $ ls new-repo.git/
Setting up Apache for Git
Creating an Apache Password File
- The following code creates the password file with the username paultester:
$ cd /c/xampp $ apache/bin/htpasswd.exe -c security/git.htpasswd paultester Automatically using MD5 format. New password: ******* Re-type new password: ******* Adding password for user paultester
Adding Git Settings
XAMPP splits its Apache configuration settings into a main httpd.conf
file and some extra files for special purposes.
- Ensure
mod_cgi
,mod_alias
, andmod_env
are enabled (httpd.conf
). - Create a new file
C:\xampp\apache\conf\extra\httpd-git.conf
:
<Directory "C:/Program Files/Git/libexec/git-core/"> Options +ExecCGI Allow From All </Directory> SetEnv GIT_PROJECT_ROOT C:/xampp/htdocs/git SetEnv GIT_HTTP_EXPORT_ALL SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER ScriptAlias /git/ "C:/Progra~1/Git/libexec/git-core/git-http-backend.exe/" <LocationMatch "^/.*/git-receive-pack$"> Options +ExecCGI AuthType Basic AuthName "Git" AuthUserFile "C:/xampp/security/git.htpasswd" Require valid-user </LocationMatch> <LocationMatch "^/.*/git-upload-pack$"> Options +ExecCGI AuthType Basic AuthName "Git" AuthUserFile "C:/xampp/security/git.htpasswd" Require valid-user </LocationMatch>
- Edit the
httpd.conf
file and append including the new extra config file:
# File: C:\xampp\apache\conf\httpd.conf # Git repositories Include "conf/extra/httpd-git.conf"
- Restart Apache
Creating a local repository
- Switch to your development PC
- Create an environment variable
HOME
which points to your home directory, e.g.C:\Users\paultester
$ cd /c/projects $ git init new-repo $ cd new-repo/
- Add the remote in your local repository
- Replace with the webserver's hostname:
$ git-config remote.upload.url \ http://paultester@<servername>/new-repo.git/
- Add some code to your repository:
$ echo "Some text..." > README $ git add . $ git commit -m "Initial commit"
- Push the repo to the webserver:
$ git push upload master Counting objects: 5, done. Writing objects: 100% (3/3), 252 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To http://paultester@localhost/git/new-repo.git c33709a..6b2ac51 master -> master
Tips and Tricks
- Continuously monitor the apache
access
anderror
log files:
$ tail -f /c/xampp/apache/logs/{access,error}.log &
To avoid to always enter the password, create a filer _netrc
ìn your %HOME%
directory:
machine <servername> login paultester password <paulspassword>
- Replace
<servername>
with the webserver's hostname and<paulspassword>
with your password.
If you use a proxy to access the internet, but don't require one to access the webserver holding the remote rpositories, add this to your local repo's `.git/config``file:
[remote "upload"] url = http://paultester@localhost/git/new-repo.git proxy =
Additional Reading
- git-http-backend Manual Page
- How to setup git server over http
- Make Git acceppting your
_netrc
file (stackoverflow): here and here
Comments
No comments