Setting Up git-http-backend with apache 2.4

2019-05-28 01:59发布

Im trying to set up a git server using git-http-backend and apache 2.4 I found this question about the same thing which was helpful, but I'm still reaching a point where I'm stuck.

I've installed git and apache2 on Ubuntu 16.04 and added the needed modules using

sudo a2enmod cgi alias env

Then added the following snippet in /etc/apache2/apache2.conf :

<VirtualHost *:80>
    SetEnv GIT_PROJECT_ROOT /var/www/git
    SetEnv GIT_HTTP_EXPORT_ALL
    SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
    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))$" \
      "/usr/lib/git-core/git-http-backend/$1"
    Alias /git /var/www/git
    <Directory /usr/lib/git-core>
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

Note that /var/www/git is where I intend my repos to go, and running

find / -name git-http-backend shows /usr/lib/git-core/git-http-backend

Next, inside of /var/www/git/ I created a directory myrepo.git and set it up as such:

sudo git init --bare --shared
sudo cp hooks/post-update.sample hooks/post-update
sudo git update-server-info

Next, I have to change the ownership of the directory to the apache2 owner (Im told). Running ps aux | egrep '(apache|httpd)' returns the following:

root 3087 0.0 0.4 73688  4928 ? Ss 02:37 0:00 /usr/sbin/apache2 -k start
www-data 3455 0.0 0.5 362836  5852 ? Sl 03:13 0:00 /usr/sbin/apache2 -k start
www-data 3456 0.0 0.5 362836  5852 ? Sl 03:13 0:00 /usr/sbin/apache2 -k start
git 3531 0.0 0.0 14512 932 pts/1 S+ 03:19 0:00 grep -E --color=auto (apache|httpd)

Now I'm not sure, because it looks like both root and www-data are running something, but I have currently decided to set the ownership to www-data (maybe it should be root?). www-data's group is also www-data (I think)

$ id www-data
uid=33(www-data) gid=33(www-data) groups=33(www-data)

so I use that to set ownership:

sudo chown -R www-data:www-data .

I also seem to remember reading that the whole path has to belong to the apache user so just for good measure I set

sudo chown -R www-data:www-data /var/www

Now from my localmachine I am trying to clone the myrepo:

git clone http://<ip-address>/myrepo.git

And I am getting the error:

fatal: unable to access 'http://<ip-address>/myrepo.git/': The requested URL returned error: 503

Can anybody see what Im doing wrong?

1条回答
萌系小妹纸
2楼-- · 2019-05-28 02:21
Alias /git /var/www/git

That should mean your urls should include /git in it:

git clone http://<ip-address>/git/myrepo.git

I don't see such an alias in this Apache configuration

查看更多
登录 后发表回答