Daniel Rench

Web application development : Servers : Networks : E-Mail : DNS : Databases : Programming for hire

previous : contact : linkedin : code : links : pictures : facebook : twitter

Git on GoDaddy

"Could you help me with my web site?"
"Where's it hosted?"
"GoDaddy! Here's the FTP login."

Don't get depressed. It's possible to make even GoDaddy's entry-level Linux shared hosting tolerable by enabling ssh and installing git, even though they seem to go out of their way to make it difficult.

The first thing to do is activate ssh for the account. It's not on by default, and you have to jump through some hoops to activate it. Log in to the GoDaddy hosting control panel for the domain. Currently, that means log in at the top of GoDaddy's home page, and then click My Account. From this page, find the My Products section and click on Web Hosting. You should soon see a list of hosted domains, with a LAUNCH button for each. Click the LAUNCH button for the domain you're working with and you will soon arrive at the "Hosting Dashboard". Locate the "Settings" tab and find the section labeled "SSH". Jump through the hoops to enable it (I needed to provide a phone number) and wait.

Take a break. It may be 10 minutes before ssh is actually working.

Remember that FTP login information? That username and password will work for ssh and sftp. You'll need to use it once, when you log in to put your ssh public key in ~/.ssh/authorized_keys. I'm going to assume you're familiar with ssh keys and won't go into how to generate them, manage them, work with ~/.ssh/config, ssh-agent, etc.

There is one twist: you need to add a command= section to the line containing your public key so it looks something like this (all on one line):

command="if [[ \"x${SSH_ORIGINAL_COMMAND}x\" == \"xx\" ]]; then /bin/bash; else source ~/.bashrc; eval \"${SSH_ORIGINAL_COMMAND}\"; fi; " ssh-rsa AAAAAAA+YOUR+KEY+GOES+HERE...

You need this for your .bashrc to have any effect on non-interactive shells (as you do when using git remotely). Your account probably doesn't even have a .bashrc yet, but it will soon.

So yes, you'll be using bash, the MSIE of shells, and probably a fairly old version as well. Considering the crippled environment (they even took which away from you, to make it even more difficult to know what you're missing) you're going to want to spend as little time in this shell as possible anyway.

Now let's get git.

Find out what Linux distribution GoDaddy gave you. uname -a says I'm on an i386 machine, and /etc/redhat-release says I'm on CentOS 5.5. If you're on something else (like a Debian derivative), you're on your own. Sorry!

Point your browser at RepoForge's collection of git RPMs and download the most up-to-date version of git available for your account's OS version and architecture. In my case, that was git-1.7.6.4-1.el5.rf.i386.rpm. GoDaddy may have given you wget so either use that to grab it, or fetch the package some other way and sftp it to your $HOME directory on the GoDaddy server.

Time to unpack. Fortunately, GoDaddy gives us rpm2cpio and cpio. I'm going to put things under ~/opt/:

% mkdir ~/opt && cd ~/opt
% rpm2cpio ~/git-1.7.6.4-1.el5.rf.i386.rpm | cpio -id
% ~/opt/usr/bin/git --version
git version 1.7.6.4

Hooray. We're almost there. Add this to your ~/.bashrc (or create one; this account I used didn't have one):

PATH=$PATH:$HOME/opt/usr/bin
export PATH

GIT_EXEC_PATH=$HOME/opt/usr/libexec/git-core
export GIT_EXEC_PATH

We need to set GIT_EXEC_PATH, otherwise git (the version I installed, anyway) will expect to find its 'core programs' under /usr/libexec/git-core.

Log back in with ssh to verify that git is working:

% mkdir ~/testrepo
% cd ~/testrepo
% echo 'This is a test' > README.txt
% git init
warning: templates not found /usr/share/git-core/templates
Initialized empty Git repository in /home/content/XX/YYYYYYY/testrepo/.git/
% git add README.txt
% git commit -m 'initial version'
[master (root-commit) 5214f3b] initial version
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 README.txt

Ignore the warning about templates not being found. Git should work fine without them, and if you want them, they're under ~/opt/usr/share/git-core/templates.

Open a new shell locally and verify that you can work with git remotely over ssh:

% git clone godaddy-host.example.com:~/testrepo
Cloning into testrepo...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

Don't you feel relieved now? If you're like me, you're going to want to use the rpm2cpio technique to install other missing essentials like rsync and make (to install CPAN modules, which could be, and may become, a whole new posting).

<< phemca, a JavaScript-to-PHP5 compiler (written in Ruby) | Home | Portfolio | Contact