Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

using Git::Wrapper with Apache

by tomgracey (Scribe)
on Jun 12, 2013 at 08:09 UTC ( [id://1038404]=perlquestion: print w/replies, xml ) Need Help??

tomgracey has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I am putting together an ajax web application and have decided to use Git behind the scenes.

Git::Wrapper seems the obvious choice but I am having some trouble when this is used through apache. E.g. if I run the following from the command line:

#!/usr/bin/perl use strict; use Git::Wrapper; my $git = Git::Wrapper->new('/path/to/repo'); my @log = $git->log; print "Content-type: text/html\n\n<!DOCTYPE html><html><body><ul>\n"; print "<li>id: ${\$log[0]->id}</li>\n"; print "<li>author: ${\$log[0]->author}</li>\n"; print "<li>date: ${\$log[0]->date}</li>\n"; print "<li>message: ${\$log[0]->message}</li>\n"; print "</ul></body></html>";

it works as expected delivering the web page to the terminal - however, when run in the browser it complains:

open3: exec of git version failed at /usr/local/share/perl5/Git/Wrappe +r.pm line 112.

Not a terribly informative error message! I've checked file permissions and am pretty sure these are not the issue. Beyond this I am stumped (the Git::Wrapper documentation does seem a little on the thin side).

Before I start wading through the module code to try and figure out what it is trying to do at the point when it falls over, I wondered if anyone had any experience of using Git::Wrapper with apache and could point me in the direction of what I need to do to get this to work?

Many thanks!

Replies are listed 'Best First'.
Re: using Git::Wrapper with Apache
by Anneq (Vicar) on Jun 12, 2013 at 11:33 UTC

    When you run the script at the command line, git is using your account and permissions. When you are executing the script through a browser, it is using whatever user, permissions and environment variables, like path, are set up for the apache server.

    Maybe you need to pass the path to the git binary location, as that might not be in the environment variables used by apache:

    my $git = Git::Wrapper->new({ dir => '/path/to/repo' , git_binary => +'/path/to/git' });

    Anne

      james2vegas and Anne, thanks for your suggestions. Pretty sure its not the path, they look essentially the same either way - however to be extra sure I tried setting it at the beginning of the program

      $ENV{'PATH'} = ...

      the result was the same.

      I have previously also tried specifying 'git_binary' as you suggested

      my $git = Git::Wrapper->new({ dir => '/path/to/repo' , git_binary => ' +/path/to/git' });

      which gives me the same: works on the command line, but falls over

      [error] open3: exec of git version failed at /usr/local/share/perl5/Gi +t/Wrapper.pm line 112

      in the browser.

      Perhaps it is one of the other environment variables - but no idea which one! I will have a look. Thanks for your help anyway.

      EDIT: forgot to mention, apache is not chrooted

        This node 1034122 has instructions on how to determine exactly which environment variables and paths are used at the command line and by apache.

        HTH

        Anne

Re: using Git::Wrapper with Apache
by james2vegas (Chaplain) on Jun 12, 2013 at 09:44 UTC
    Not sure how obvious a choice Git-Wrapper is, there are other modules that do it, including Git which is shipped with git itself.

    That said, your error suggests that git is in some way unreachable, i.e. probably not in your PATH or your Apache might be chrooted.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1038404]
Approved by hdb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-25 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found