Installing Git on a cPanel Server

Installing Git on a cPanel Server



Most software developers will be familiar with version control systems and their powerful ability to manage and share code throughout organisations or projects; however, many web developers may not have the same experience. One of the most popular version control systems today is called Git.

One of the great advantages of git is that every developer working on the project has their own copy of the code, meaning minor bugs during development will not negatively affect the main codebase or other developers working on it at the same time. In this post, I’m going to explain how you can install Git on your cPanel VPS so that multiple developers can work on a single project without accidentally overwriting each other’s files or adding conflicting code.

On non-cPanel servers, the process has always been straight forward, Git has been installed simply by using Yum (for Redhat based distributions) or apt-get (for Debian). However, until recently, it has not been possible to install Git via RPM on cPanel servers as cPanel installs its own versions of Perl libraries on the server. Git required updated Perl packages which are likely to break cPanel/WHM. cPanel staff have specifically noted in forum threads that they do not recommend installing Git due to the potential problems it can cause. Recently, cPanel have responded to a feature request to add a cPanel compatible RPM, however there are still issues reported with this solution so I would recommend not testing this on a production machine, and following the below installation instructions instead.

SSH into the server and download the latest version of the git source. If you want to install git server-wide, you should run the following commands as root, otherwise, login as the specific user for which it is to be installed.

$ wget http://git-core.googlecode.com/files/git-1.8.2.1.tar.gz

Now untar it and cd into the directory it creates

$ tar fxzv git-1.8.2.1.tar.gz

$ cd git-1.8.2.1

Now we need to compile Git by running the following commands. Note the following configure option specifies that it will be installed in the home directory and not server-wide.

$ ./configure –prefix=/home/$USER

If you would rather install Git server-wide so that all users can access it, you will need to change the above line to the following:

$ ./configure –prefix=/usr

Once the configure command has completed, it’s time to compile and install the software with the following two commands:

$ make

$ make install

If you installed it as root, you should now be able to run all the standard git commands, however, if you chose the per-user install, you will need to make sure that your /home/user/bin directory is in your executable path with the following commands:

$ echo ‘PATH=$PATH:$HOME/bin’ >> $HOME/.bashrc

$ source $HOME/.bashrc

Done! Git is now installed on your server. If you have never used it before, there is some great documentation out on the web. For getting started creating, managing and using git repositories, you should check this documentation. If you’re looking for a more in-depth history and theory of Git and version control systems more generally, you might be game to read the Pro Git book freely available online.

 



  • Adrian

    The problem is this cannot be done on crucial shared hosting because the jailed ssh does not have the compiler. The alternative is to compile git on a similar server and copy it to the web hosting.

  • Git is now installed on cPanel (since version 11.36) in the 3rdparty bin directory, /usr/local/cpanel/3rdparty/bin.

    Just add that directory to your user’s PATH and they can use git as a command.

  • Skelly

    If you are just wanting simple git client access using the version deployed with cPanel (as of 11.36+) via a simple symlink (if you already have root accessto the server) seems easier.

    See http://stackoverflow.com/questions/18518279/installing-git-on-a-cpanel-server#comment27255862_18528174

  • Thomas Wilson

    G’day

    Thanks for the interesting article.

    I’m keen to set up git to manage changes between locally developed wordpress sites and then push to live server

    Will this new feature new feature benefit my quest?!

    Thanks
    T