This article will show you how to deploy your git repo into a shared environment using Arvixe. This article was originally written by Arlo Carreon over at his website. Stop by and take a look!
Git is rapidally becoming more and more popular; and while Github is a great way to store your projects, you will need a way to deploy your web app to your shared hosting. Arvixe is one of the most affordable and reliable shared hosting providers I’ve come across and a perfect example for demonstrating how to deploy your git repo into a shared environment.
1.) Setup SSH Access with Arvixe
Make sure you have SSH access. Shared hosting accounts with Arvixe do not come with SSH access by default. You will to go to the support chat and ask for SSH access, this will only take minutes and is effective immediately. Once they give you access, make sure you can login. Here is how you would SSH into your account with your Arvixe username and password.
[tage lang=”bash”]
ssh USER-NAME@your-domain.com
…
Enter your password: *********
[/code]
Get your public key into Arvixe.Your public key is located on YOUR computer, ~/.ssh/id_rsa.pub.
Create the following file on Arvixe and copy the contents of your public key into this new file: ~/.ssh/authorized_keys.
Incase you don’t have ~/.ssh/id_rsa.pub on your computer, run ssh-keygen in your console and hit enter all the way through. At the end of that, you will have the ~/.ssh/id_rsa.pub file on your computer.
You can create a new file on Arvixe with the following command: touch ~/.ssh/authorized_keys.
Configure your repo on Arvixe. First, you need to set a config option in your Arvixe repo to accept pushes into this working directory. While SSH’d into your Arvixe account, navigate to your repo directory and run this command:
[code lang=”bash”]
git config receive.denyCurrentBranch ignore
[/code]
Finally, you need to set a git hook that will refresh your working directory after the push has been accepted. Save the following content in:
[code light=”true” highlight=”1″ lang=”plain”]PATH_TO_REPO/.git/hooks/post-receive[/code]
.
[code lang=”shell”]
#!/bin/sh
# Save this in: PATH_TO_REPO/.git/hooks/post-receive
GIT_WORK_TREE=../ git checkout -f
[/code]
Then, make it executable with
[code light=”true” highlight=”1″ lang=”plain”]chmod +x PATH_TO_REPO/.git/hooks/post-receive[/code]
2.) Setup Your SSH Config Locally
Automate SSH connection for your Arvixe account.
In order to add Arvixe as a git remote, you want to setup your username as the default and you will not be using your password for authentication. You need to edit/create the file ~/.ssh/config on your computer. Then add this content.
[code language=”shell”]
Host your-domain.com
User YOUR-ARVIXE-USERNAME
PreferredAuthentications publickey
[/code]
Now, you should be able to login with ssh your-domain.com without needing to type your password or include your username. If this is not the case, start over at step 1.
3.) Setup Arvixe Account as a Git Remote
Add your domain as a remote. On your computer, navigate to your git repo and run this command.
We are assuming your git repo is in WWW. In reality, your repo can be anywhere on your Arvixe account, just change “www” with the correct path below.
[code lang=”bash”]
git remote add arvixe-live your-domain.com:www/
[/code]
Now, you can make your changes to your repo and when you are ready to push your changes:
[code lang=”bash”]
git push arvixe-live master
[/code]
Something to think about
With this setup it is now easy to have a “dev” site on your Arvixe account too. SSH into Arvixe and replicate your repo into a different folder (~/www/dev). Locally, setup a new remote:
[code lang=”bash”]
git remote add arvixe-dev your-domain.com:www/dev
[/code]
So, from now on you can git push arvixe-dev to test out your new changes. When you are ready to make your changes live: git push arvixe-live.
Hey, great step by step. Here is one missing step though, and thought it could be useful to others:
After this step:
Configure your repo on Arvixe. First, you need to set a config option in your Arvixe repo to accept pushes into this working directory. While SSH’d into your Arvixe account, navigate to your repo directory
And before you execute the next step, you may need to initialize Git if you haven’t used it before.
To do that, run this command:
git init
Then do the next step (pick up right where you left off), run command:
git config receive.denyCurrentBranch ignore
And just continue with the rest of this tutorial.
Hey, thanks again, it was a huge help!
Does this works with the New Windows 2012 servers?
Hi, Unfortunately it is only for our shared Linux servers. If you have an ASP VPS you can install Git for Windows. Regards.