Installing a git client on a shared host with no compiler

GIT LogoWe are using Git to manage our deployments, but have some clients that use shared hosting services that don’t have git installed (in particular Hostgator.com).
Hostgator Logo
Most of these shared hosting services do allow ssh shell access but don’t have compilers available on the shared hosting account. So I couldn’t just build git on the shared hosting account.

Many hosting services do offer webdav access to the account’s filesystem. I tried pushing git trees to the target filesystem over https/webdev, but couldn’t get it to work even if I first copied a bare git directory to the target.

This left me with the thought that maybe I could build git on another host that I controled that had the same type of Linux environment that was running the target shared host environment. Once I built it in the environment I controled, I could then copy it to the shared hosting account and use it via ssh shell access.

CentOS Logo
In the particular case of Hostgator, they were running CentOS 5.2.Thus I needed a CentOS 5.2 machine to build Git on. I didn’t have one lying around, but I do have an Amazon EC2 account!
(You should be able to modify this to work with other Linux versions pretty easily.)

Create a CentOS 5.2 instance on Amazon EC2

Used the Amazon Machine Image ami-0459bc6d described in CentOS 5 i386 Base AMI posting which includes instructions on how to instantiate and update to CentOS 5.2.Amazon Web Services Logo

I used the fabulous ElasticFox extension to Firefox to instantiate and run the base image.

Documentation on using ElasticFox can be found at Elasticfox Getting Started Guide. Documentation on using Amazon EC2 can be found at Amazon EC2 Getting Started Guide.

I won’t repeat those instructions here, you’ll have to get the Amazon EC2 basics from those docs.

One you have the base ami-0459bc6d instance running, there are a few things you must do to to the stock CentOS 5.1 image to get it ready to build git:

Update the CentOS image from 5.1 to 5.2

yum -y upgrade
reboot

Install gcc

yum install gcc

Install zlib-devel package

Noticed that zlib-devel was needed by the git install process when I first tried to run configure on the git distribution.

yum install zlib-devel

Install curl-devel

Needed if you want to use http/https/webdav access to git repositories.

yum install curl-devel

Build Git from Source

Once you have got your CentOS 5.2 system running, you can build git from the source tree.

Download git

wget http://kernel.org/pub/software/scm/git/git-1.6.0.4.tar.gz

Unpack the Git source tree

tar xvzf git-1.6.0.4.tar.gz

Create a build target path

You will need to have a build target directory path on your build machine that is the same as the path to your home directory on your target virtual host account. In this example we’re calling it
/home/clientname.

Replace clientname with the name of your home directory on hostgatore which is usually the same as your domainname.

This is where the build/install process will end up “installing” the compiled and other run time files:

mkdir /home/clientname

Run Configure on source tree

Change directory on the build machine to the top of the git source tree. (Where you unpacked the tar file git-1.6.0.4.tar.gz it does not have to be in /home/clientname)

cd git-1.6.0.4

Configure and set the prefix to the home directory that is your home directory on the target virtual host.

./configure --prefix=/home/clientname/git_root

Build the code and have it be installed in the directory that you defined in the –prefix line above
make
make install

Assuming all goes well, it will build the code in the directory

git-1.6.0.4

and install everything in the directory

/home/clientname/git_root

It will automatically create the git_root directory but you have to have created /home/clientname

Tar it up and scp it to target

cd /home/clientname
tar cvzf git_root.tgz git_root
scp git_root.tgz userid@clienturl:

Unpack it on target

ssh userid@clienturl
tar xvzf git_root.tgz

Set up environment to use the newly installed git

Add the path to the newly created bin to your path:

Edit your startup file such as ~/.bash_profile and add:

PATH=/home/clientname/git_root/bin:$PATH

You have to log out and log back in or source .bash_profile to update the path. You can also type that line into your current session at the prompt and have it immediately active.

Use Git as normal!

I found that I can now use Git as normal except that with Hostgator they seemed to be blocking the git protocol or something. I could not say:

git clone git://github.com/rberger/project.git

But I could say:

git clone git@github.com:rberger/project.git

(assuming I had my ssh keys setup to access github as git)

or

git clone http://github.com/rberger/project.git

Note that you do not say ./git. We are assuming that you added git to your path and you can just say git and it will find the executables via the $PATH

If you didn’t want to change $PATH, you could  give a full path like:

/home/clientname/git_root/bin/git clone git@github.com:rberger/project.git

Save your CentOS 5.2 Amazon Image

If you want to, you can save the CentOS 5.2 customized image you created on Amazon EC2.

Ssh into the root account on your running CentOS amazon instance, copy your Amazon EC2 certificate and private key to the home directory of root on the running CentOS instance and run the following commands:

Build the new AMI

Replace cert-your_cert_sig.pem, your-private-key-sig and your-amazon-userid with the appropriate values for your EC2 certificate.

ec2-bundle-vol -d /mnt --cert cert-your_cert_sig.pem --privatekey pk-your-private-key-sig.pem -u your-amazon-userid -s 3096

The -s 3096 tells it to create an image that is 3GB big. You may have to make it bigger if the command fails. You can check that this is the problem by adding the –debug flag to the above command.

Stash the image into your S3 account

Use your own ws-access-key-id and aws-secret-access-key

ec2-upload-bundle -b centos-5.2-git -m /mnt/image.manifest.xml -a aws-access-key-id -s aws-secret-access-key

Git to your hearts content!

Here is the gzipped tar file of git built to run on hostgator. I don’t know if it will work in any other directory than the one it was built for though.

git_root.tgz

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • Slashdot
  • Suggest to Techmeme via Twitter

15 comments to Installing a git client on a shared host with no compiler

  • jean

    Very interesting.
    I wonder if all git commands work, including creating repositories and push from outside (eg our local computers) without being blocked by HG.

  • jean

    there might be a missing step about git_root

  • Nice article. I was wondering if you could post your build with this article? I have a similar web provider that uses the same platform. Using your build would save me some time.

  • Shu

    Can you still run git on hostgator? I just did a git build similar to what you described to be run on hostgator, but I’m getting “-jailshell: ./git: cannot execute binary file”

  • Sorry hadn’t seen these comments till now!

    @jean: I don’t think that you can push to hostgator (I think I had tried it when I first did it). It might work if you did the git via ssh mode though. But all the other stuff where you are pushing and pulling from the hostgator seems to work for me (at least the things I need to do)

    It does look like I did not complete the part about git_root. I will fix that shortly. Not sure what happened there!

    @Dan Van Derveer Did you want the Amazon AMI or the tar of the built git_root? I might be able to do both.

    @Shu; I can still run git on hostgator. I just checked.
    You need to put the where the new git is located into your path

    PATH=/home/clientname/git_root/bin:$PATH

    and execute it without the ./ in front. And/or use the full path to git like:

    /home/clientname/git_root/bin/git

  • I’ve updated the post so that it completes the instructions on how to install the git_root. Also included a link to the built tar file, though it may only work in my directory.

    I also made the Amazon AMI I used public: ami-5759be3e

  • Your build works and i’ve added it to the $PATH.
    Everything except git pull works and I was wondering if you had any idea about it.
    $ git pull origin master
    git: ‘pull’ is not a git-command. See ‘git –help’.

  • Weber

    I am using godaddy shared hosting. I copied the git_root.tar here and almost everything worked… To make it fully working I need to “ssh out” (I mean run ssh from my godaddy bash)
    Typing ssh gives me ‘permission denied’.

    Do you mind packing openSSH (or any ssh client) as you did with GIT? I would be very thankful!

  • Dennis Gascoigne

    Also, if you get a template error
    templates not found ~/git_root/share/git-core/templates/

    Try
    git init –template=/home/clientname/git_root/share/git-core/templates/ –bare

  • Roy

    I am using hostgator as well to try GIT.
    SSH is enabled and I can connect to it.
    But when I try to push I get the error it requires a port.
    Even if I put it likes this:

    git remote add origin user@hostname:2222:/dir/to/gir/repo
    git push origin master

    It says it requires a port.
    Note that I can connect with the server via ssh with the command:

    ssh user@hostname -p 2222

    Can you help me out please?
    I am deseprate cause I searched for almost 3 hours on google now without any succes.

    Thanks.

    Regards,
    Roy

  • Brother, make this:

    git remote add origin ssh://user@hostname:2222:/dir/to/gir/repo

  • My good Robert,

    Thanks for the great article. I tried to download your file but got a 404.
    Is it still available?

    Thanks in advance,
    Luciano

  • I suspect I lost that file in various upgrades of my blog. I will look for it though.

  • Craig

    Dear Robert,

    Thank you for a great article.
    I am looking for a Git executable to run on Centos 5.6 and would appreciate a pre-compiled file.

    Many Thanks,

    Craig.

  • Craig: I don’t seem to have any of the files any more…

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>