Amazon Ad

Wednesday, 22 January 2014

How to create a GitHub Hook to update my website from GitHub Push.



Step 1 Generate a ssh key on the server and copy that ssh keys into the .ssh\id_rsa file. Also add the public key in file id_rsa.pub into your github repository under settings and ssh keys.

Step 2 On the server install git.

Step 3 On the github make sure you have a repository and create a branch named "development".

Step 4 Push all your project files onto your repository and in "development" branch.

Step 5 Pull the files from the github respository into your server's folder. Also make sure that you have sufficient rights for this folder i.e IUSR user should have sufficient rights.




Step 6 On the client create a file name "deploy.php" and push it on to the "development" branch. Now on server use git pull command to get the updated file into your directory where .git and other php files are residing, i.e your website folder.

Here is "deploy.php"
<?php
$repo_dir = 'C:\www\test.com';
exec('cd ' . $repo_dir);
exec('git checkout development');
shell_exec('git pull');
die('done');
?>

Step 7 Now go to github and click on settings and service hooks, Now add a web hook url i.e www.test.com/deploy.php.

Step 8Push on the "development" branch and the changes you have made on the github will be reflected on the website.

Please note on server the sh.exe looks for the keys in C:\Windows\SysWOW64\config\systemprofile\.ssh. So I copied everything in C:\Users\Administrator\.ssh to that folder and it worked perfectly.Thanks to user "Iamz" http://stackoverflow.com/questions/8117028/git-pull-via-php-exec-iis

That's It Enjoy!!

No comments:

Post a Comment

Comments are welcome, Please join me on my Linked In account

http://in.linkedin.com/pub/ritesh-tandon/21/644/33b

How to implement Captcha v3 in ASP.NET

 I was facing an issue of dom parsing in my website. I finally resolved it by using Google Captcha V3. Step 1: Get your keys from https:...