We 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).
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.
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.
I used the fabulous ElasticFox extension to Firefox to instantiate and run the base image.
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
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
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.
Unpack the Git source tree
tar xvzf git-22.214.171.124.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
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:
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-126.96.36.199.tar.gz it does not have to be in /home/clientname)
Configure and set the prefix to the home directory that is your home directory on the target virtual host.
Build the code and have it be installed in the directory that you defined in the –prefix line above
Assuming all goes well, it will build the code in the directory
and install everything in the directory
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:
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 firstname.lastname@example.org:rberger/project.git
(assuming I had my ssh keys setup to access github as git)
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:
git clone email@example.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.