Lloople
Lloople

Reputation: 1844

How to set up a Git server with HTTP access on Linux

I need to create a Git repository on a Linux machine and then make it accessible via HTTP. Also need full access with one user and read-only to anon-users.

I've created local repositories before but I don't know how to create this (e.g.: inside /var/www or /opt/git/...)

I tried doing this:

-sudo Clone a GitHub repository into /var/www/repos/repo.git
-cd /var/www/repos/repo.git
-sudo git --bare update-server-info
-sudo mv hooks/post-update.sample hooks/post-update
-sudo service apache2 restart

Then I tried to access this repository from another machine:

-With browser : (http protocol)192.168.1.49/repo.git <-- WORKS
-With terminal: git clone --bare (http protocol)192.168.1.49/repo.git <--DOESN'T WORK

The terminal says:

Cloning into bare repository repo.git... fatal: (http protocol)192.168.1.49/repo.git/info/refs?service=git-upload-pack not found: did you run git update-server-info on the server?

I think maybe it's a permissions problem. How I need to manage permissions inside /var/www?

EDIT: Already fixed, just needed:

-put the repository into /var/www/repos/ named repo.git
-change the permissions of the www folder with sudo chown -R www-data:www-data /var/www
-enable webdav with sudo a2enmod dav_fs
-config file into /etc/apache2/conf.d called git.conf
-create the file with users with sudo htpasswd -c /etc/apache2/passwd.git user
-rename the pot-update file and make it executable with sudo mv /var/www/repos/repo.git/hooks/post-update.sample /var/www/repos/repo.git/hooks/post-update && sudo chmod a+x /var/www/repos/repo.git/hooks/post-update
-update server and restart apache with sudo git update-server-info && sudo service apache2 restart

And, to fix the problem with pushing:

Edit the file .git/config into your repository folder (client machine) and put the username and password on the url:
url = (http protocol)user:password@url/repos/repo.git

So, now only I need is to set the read-only for anon-users.

Upvotes: 1

Views: 5502

Answers (1)

Lloople
Lloople

Reputation: 1844

Already fixed, just needed:

-put the repository into /var/www/repos/ named repo.git

-change the permissions of the www folder with sudo chown -R www-data:www-data /var/www

-enable webdav with sudo a2enmod dav_fs

-config file into /etc/apache2/conf.d called git.conf

-create the file with users with sudo htpasswd -c /etc/apache2/passwd.git user

-rename the pot-update file and make it executable with sudo mv /var/www/repos/repo.git/hooks/post-update.sample

/var/www/repos/repo.git/hooks/post-update && sudo chmod a+x

/var/www/repos/repo.git/hooks/post-update

-update server and restart apache with sudo git update-server-info && sudo service apache2 restart

And, to fix the problem with pushing:

Edit the file .git/config into your repository folder (client machine)

and put the username and password on the url: url = (http

protocol)user:password@url/repos/repo.git

So, now only I need is to set the read-only for anon-users.

Upvotes: 1

Related Questions