Part 1: Python on DreamHost: Part 1 - Custom Installation
This is the second part in a sequence on DreamHost (disclosure: affiliate code on that link) customization. There are a lot of pre-configured capabilities out of the box, but if you really want to stretch your dollars you can squeeze a lot more from their shared host service.
All developers need some form of source version control. DreamHost has a one-click install for Subversion, which works very nicely. It is easily installed and managed directly from the Web Panel. But what about Git? There is no out of the box support and while most shared servers may have an old version installed, you are left to update/configure it yourself.
Tiago Macambira has a very comprehensive guide up on GitHub that covers most of this and includes scripts to make life easier as well. Check out his tutorial: Private GIT repositories (on DreamHost).
I followed his guide heavily, but decided on two main changes:
Read on to see where I deviated from his steps.
Before starting on the guide, I wanted to make sure I had the latest version of Git. Tiago mentions that its likely your server already has some version of Git installed. This was true for mine. To find out what version, SSH in and run:
$ git --version
git version 1.7.2.5
Great, its already there and we could definitely proceed with this. However, I'm going to install the latest version (2.1.0 as of this writing) and use that for my repository.
$ cd ~
$ wget https://www.kernel.org/pub/software/scm/git/git-2.1.0.tar.gz
$ tar xvzf git-2.1.0.tar.gz
$ cd git-2.1.0
$ ./configure --prefix=$HOME/.git2.1.0 NO_CURL=1 NO_MMAP=1
$ make
$ make install
A couple notes about these commands. NO_CURL=1
tells the make file to use WGET instead of Curl. NO_MMAP=1
turns off Git's mmap to make it compliant with DreamHost's persistent process policy for shared servers (basically, do not cache large files in memory).
After the install is complete, git --version
again reveals the system is still using the old build. We will fix that by updating bash. But first, let's clean up the install files:
$ cd ..
$ rm git-2.1.0.tar.gz
$ rm -r git-2.1.0
Next, change directory to your Home and edit .bashrc
to ensure all non-login shells use the correct version of Git.
$ cd ~
$ vi .bashrc
# In VI, press i to insert, and add the line:
export PATH=$HOME/.git2.1.0/bin:$PATH
# then press Esc to cease insert, and :wq to save and exit
Save the changes. Now edit .bash_profile
to load .bashrc
. This ensures all login shells also use the correct version of Git:
$ vi .bash_profile
# In VI, press i to insert, and add the lines:
if [ -f $HOME/.bashrc ]; then
source $HOME/.bashrc
fi
# then press Esc to cease insert, and :wq to save and exit
Save the changes and reload the .bash_profile
:
$ source ~/.bash_profile
Now, finally we can try git --version
again, and we will be rewarded with git version 2.1.0
!
You can follow the GitHub guide almost verbatim from this point. Here are a few gotchas based on how I wanted things configured.
Instead of using a directory in an existing domain, I chose to host my git repository in an entirely separate sub-domain: git.example.com
. I placed my web directory in a~/git/git.<example>.com
After filling in the settings, click 'Fully host this domain.'
Switch back to shell, and change directory to your newly created web directory. Once there, create an .htaccess
file and give it the following permissions:
$ cd ~/git/git.<example>.com
$ touch .htaccess
$ chmod 644 .htaccess
You can continue on with the guide as normal from this point to set up the .htaccess
file.
Make sure you use the correct git-http-backend
path in git-http-backend-private.cgi
. This is because we are not using the default installation. If you followed my setup above, you need your CGI file to point to the following:
/home/<user>/.git2.1.0/libexec/git-core/git-http-backend
Now we can create a sample repository to make sure everything is working. On the server, run the shell script:
$ cd ~
$ ./newgit.sh -d "A Sample Repository" -n sample-git-repo.git
And on your local machine, clone the new repository:
> git clone http://username@git.<example>.com/sample-git-repo.git
Cloning into 'sample-git-repo'...
Password for 'https://username@git.<example>.com':
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
I relied heavily on the following pages while configuring this on my own DreamHost account: