Setting up Godaddy Shared Hosting with git bitbucket

Ever wanted to control your code hosted on shared hosting like godaddy. Here is a step by step guide on how to work on bitbucket and update your godaddy files to latest commint with one click.

Problems faced during the above setup are as follows:

  1. GIT is not installed on Godaddy by default.
  2. It is difficult to host a GIT on Shared hosting with lots of restrictions.
  3. If we install git on server how we will manage our code in live and beta versions.
  4. We wanted to use bitbucket because of its unlimited free directories and easy to understand web interface to view commits/issues etc.
  5. How Bitbucket and Godaddy server will sync.
  6. Set-up one click action to update godaddy server with latest version of code.
Follow the steps below:

Step 1: SSH into Godaddy hosting
By SSH access to godaddy hosting is disabled. We can enable it by Going into hosting control panel > SSH (Under Settings) > Enable SSH.
After enabling SSH get/create a FTP username & password with access to all folders.

Godaddy Server can now be accessed using SSH.

Now setup your system to access SSH. Linux/unix system are ready to access but for windows users we will follow these steps.
  1. Open "http://git-scm.com/downloads" and download git for windows.
  2. Install downloaded git into your system with all default settings. 
  3. After installation Open "Git Bash" from start menu.
  4. type command "ssh <ftp username>@<your domain name>" press Enter
  5. You will be asked to add host to known_host list. type yes and press Enter
  6. Password will be prompted. Enter Password.
You have successfully logged into Godaddy Server try running ls.


STEP 2:   Install GIT on Godaddy server
  1. Get your server instance by following command:
    $ uname -a

    Linux xyz.secureserver.net 2.6.18-348.6.1.el5PAE #1 SMP Tue May 21 16:17:08 EDT 2013 i686 i686 i386 GNU/Linux

    Note the instance i386
  2. Get your OS Number:
    $ cat /etc/redhat-release
    CentOS release 5.5 (Final)

    Note OS and version : CentOS, 5.5(Final)
  3. Browse to http://pkgs.repoforge.org/git/ and find out the rpm to grab for the latest git version: git-1.7.9.6-1.el5.rf.i386.rpm
  4. From your home directory( cd ~/ ), get the rpm:
    $ wget http://pkgs.repoforge.org/git/git-1.7.9.6-1.el5.rf.i386.rpm

Install & Configure Git

  1. Unpack git using rpm2cpio and cpio:
            mkdir ~/opt
            cd ~/opt
            rpm2cpio ~/git-1.7.9.6-1.el5.rf.i386.rpm | cpio -id        
    
  2. Check that it is installed:
            ~/opt/usr/bin/git --version
            git version 1.7.9.6        
    
  3. Configure git to work on your path and not to do SSL verification. Create a ~/.bash_profile file, if not already existing and add the following to it:(use vi ~/.bash_profile)
            export GIT_SSL_NO_VERIFY=true
            PATH=$PATH:$HOME/opt/usr/bin
            export PATH
            GIT_EXEC_PATH=$HOME/opt/usr/libexec/git-core
            export GIT_EXEC_PATH        
    
  4. Check these settings by logging out and back in. Then check the version:
            git --version
            git version 1.7.9.6        
    
    If bash doesn't know about git, try moving those settings to the .bashrc file instead of .bash_profile.
  5. Run the following commands to properly configure git:
            $ git config --global init.templatedir ~/opt/usr/share/git-core/templates
            $ git config --global remote.origin.uploadpack ~/opt/usr/bin/git-upload-pack
            $ git config --global remote.origin.receivepack ~/opt/usr/bin/git-receive-pack
            $ git config --global user.name ""
            $ git config --global user.email ""
Test Everything by running git clone of any of your existing repo.(Use https instead of git for cloning a repo)

STEP 3:  Set-up password less authentication to Godaddy. 
If you want to update the files on Godaddy from bitbucket repo in one single click then you will need to setup password less authentication but note that Any one with access to your local system can make changes to your godaddy server.
To add password less authentication you will need to create private-public key pair. Follow the steps below:
  1. Open New "Git Bash". or type exit in previously opened Git Bash.
  2. Run "ssh-keygen -t rsa" to create private-public key pair. File name prompt will ask for file name. Press enter without entering file name. Then you will be asked to create password, press enter without entering password.
  3. Your public key will be saved in c:/user//.ssh
  4. Open id_rsa.pub in notepad.
  5. Copy its content.
  6. Login Back to Godaddy by "ssh <ftp username>@<your domain name>"
  7. type "vi ~/.ssh/authorized_keys2" this will open a vi in the same window
  8. press i to enter into INSERT mode. And take your cursor to the end of file and click on git icon on top left corner of window > Edit > Paste. this will paste your public key to authorized_keys2 file.
  9. press "Esc" and then "ZZ" this will save authorized_keys2 file.
  10. type "exit" and try logging back in. You will not be prompted for password now.
STEP 4: Set-up one click update
Everytime logging into server and run git pull command may not be productive at all. So we will now setup one click server update.

In this step we will automate the logging and git pull process.
  1. Open Notepad
  2. type following line - this login to godaddy, change current directory to your repo and run a git pull command. Note: Keep this file secret as it contains username and password of your bitbucket account.
    ssh @ 'cd ~/; git pull https://:@bitbucket.org/path/to/repo.git;'
  3. In next line type - this will enable you to see the result.
    read -p "Press Enter to Exit..." answer

To setup each user repeat Step 3 & 4 on each users system.

 UPDATE: Automated Script to commit changes in local repo, push from local repo to bitbucket repo, pull from bitbucket to live server  

Below Script will enable you to commit your local changes and push them to the bitbucket server and then pull from bitbucket to godaddy/hosting sever. Just place this file in your local repo. You can add it to gitignore for ignoring this file.

#--------change the value of branch variable to work on it ------------
branch="master" #name of branch
folder_name="/a" #name of folder in which you want to commit
#----------------------------------------------------------------------

br_nm=$branch

loop=""

while [ -z "$loop" ]
do
clear
ECHO "-------------------------------------------------------------------------------
Development Server Update Script
-------------------------Developed by Abhishek Sachan--------------------------
--------------------------abhisheksachan.blogspot.com--------------------------
-------------------------------------------------------------------------------
"
read -p "Enter Commit Message: " answer

if [ -z "$answer" ]
then
ECHO "
>>Skip Commit to bitbucket due to empty message.
"
else
git add -A .
git commit -m "$answer"
ECHO "-------------------------------------------------------------------------------
Response from GIT - bitbucket (Updating Bitbucket server)
-------------------------------------------------------------------------------"
git push https://bitbucketusername:bitbucketpassword@bitbucket.org/path/to/repo
fi
ECHO "-------------------------------------------------------------------------------
Response from Hosting Server(updating...)
-------------------------------------------------------------------------------";
ssh hosting_username@host_address.com "cd /var/www/html$folder_name; git branch $br_nm; git checkout $br_nm; git pull https://bitbucketusername:bitbucketpassword@bitbucket.org/path/to/repo $br_nm;"
read -p "-------------------------------------------------------------------------------
Press Enter to repeat and type 'exit' to Exit... : " loop
done


Change the required values highlighted in above code. And you ready to go with one click commit>push>pull>live.


    All Done Enjoy...!

    Hey Coder! Do you want to manage your time during work/wanted to know how much time you spent on Facebook/Any other website/Coding last week do read my post -How to get Productive during work. And get know more about a tool to help you on this.

    Leave your feedback in comments below:

    Comments

    1. This comment has been removed by a blog administrator.

      ReplyDelete
    2. This comment has been removed by a blog administrator.

      ReplyDelete
    3. This comment has been removed by a blog administrator.

      ReplyDelete
    4. This comment has been removed by a blog administrator.

      ReplyDelete
    5. This comment has been removed by the author.

      ReplyDelete
    6. This comment has been removed by a blog administrator.

      ReplyDelete
    7. This comment has been removed by a blog administrator.

      ReplyDelete
    8. This comment has been removed by a blog administrator.

      ReplyDelete
    9. This comment has been removed by a blog administrator.

      ReplyDelete
    10. This comment has been removed by a blog administrator.

      ReplyDelete
    11. This comment has been removed by the author.

      ReplyDelete
    12. This comment has been removed by a blog administrator.

      ReplyDelete

    13. Your complete Facial Attendance & access Control Solution at one place
      Scalable solution for your projects with reliability
      facial recognition attendance machine

      ReplyDelete
    14. This is really a nice and informative, containing all information and also has a great impact on the new technology. Thanks for sharing it. To get Linux Shared Hosting to visit the link

      ReplyDelete
    15. Thanks for it. I would like to read it more. Thank You for Providing Such a Unique and wonderful information about web hosting script.

      ReplyDelete

    Post a Comment

    Popular posts from this blog