Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deploy your site with git

Deploy your site with git

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
    • apache's home directory is /var/www/
    • (this describes a pretty standard apache setup on Redhat / Ubuntu / CentOS / Amazon AMI etc)

you should be able to do the same with Java, Perl, RoR, JSP etc. however you'll need to recreate the (rather simple) PHP script

1 - On your local machine

Here we add the deployment script and push it to the origin, the deployment script runs git commands to PULL from the origin thus updating your server

Grab a deployment script for your site

See deploy.php

Add, commit and push this to github

git add deploy.php
git commit -m 'Added the git deployment script'
git push -u origin master

2 - On your server

Here we install and setup git on the server, we also create an SSH key so the server can talk to the origin without using passwords etc

Install git...

After you've installed git, make sure it's a relatively new version - old scripts quickly become problematic as github / bitbucket / whatever will have the latests and greatest, if you don't have a recent version you'll need to figure out how to upgrade it :-)

git --version

...on CentOS 5.6

# Add a nice repo
rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
# Install git
yum install --enablerepo=webtatic git-all

...using generic yum

sudo yum install git-core

Setup git

git config --global user.name "Server"
git config --global user.email "server@server.com"

Create an ssh directory for the apache user

sudo mkdir /var/www/.ssh
sudo chown -R apache:apache /var/www/.ssh/

Generate a deploy key for apache user

sudo -Hu apache ssh-keygen -t rsa # choose "no passphrase"
sudo cat /var/www/.ssh/id_rsa.pub

3 - On your origin (github / bitbucket)

Here we add the SSH key to the origin to allow your server to talk without passwords. In the case of GitHub we also setup a post-receive hook which will automatically call the deploy URL thus triggering a PULL request from the server to the origin

GitHub instructions

Add the SSH key to your user

  1. https://github.com/settings/ssh
  2. Create a new key
  3. Paste the deploy key you generated on the server

Set up service hook

  1. https://github.com/oodavid/server.com/admin/hooks
  2. Select the Post-Receive URL service hook
  3. Enter the URL to your deployment script - http://server.com/deploy.php
  4. Click Update Settings

Bitbucket instructions

Add the SSH key to your account

  1. https://bitbucket.org/account/ssh-keys/
  2. Create a new key
  3. Paste the deploy key you generated on the server

Set up service hook

  1. Go to: Repo > Admin > Services
  2. Select "POST"
  3. Add the URL to your deployment script - http://server.com/deploy.php
  4. Save

Thanks to DrewAPicture in the comments for this one

4 - On the Server

Here we clone the origin repo into a chmodded /var/www/html folder

Pull from origin

sudo chown -R apache:apache /var/www/html
sudo -Hu apache git clone git@github.com:you/server.git /var/www/html

Rejoice!

Now you're ready to go :-)

Some notes

  • Navigate the the deployment script to trigger a pull and see the output:
  • When you push to GitHub your site will automatically ping the above url (and pull your code)
  • When you push to Bitbucket you will need to manually ping the above url
  • It would be trivial to setup another repo on your server for different branches (develop, release-candidate etc) - repeat most of the steps but checkout a branch after pulling the repo down

Sources

<?php
/**
* GIT DEPLOYMENT SCRIPT
*
* Used for automatically deploying websites via github or bitbucket, more deets here:
*
* https://gist.github.com/1809044
*/
// The commands
$commands = array(
'echo $PWD',
'whoami',
'git pull',
'git status',
'git submodule sync',
'git submodule update',
'git submodule status',
);
// Run the commands for output
$output = '';
foreach($commands AS $command){
// Run it
$tmp = shell_exec($command);
// Output
$output .= "<span style=\"color: #6BE234;\">\$</span> <span style=\"color: #729FCF;\">{$command}\n</span>";
$output .= htmlentities(trim($tmp)) . "\n";
}
// Make it pretty for manual user access (and why not?)
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>GIT DEPLOYMENT SCRIPT</title>
</head>
<body style="background-color: #000000; color: #FFFFFF; font-weight: bold; padding: 0 10px;">
<pre>
. ____ . ____________________________
|/ \| | |
[| <span style="color: #FF0000;">&hearts; &hearts;</span> |] | Git Deployment Script v0.1 |
|___==___| / &copy; oodavid 2012 |
|____________________________|
<?php echo $output; ?>
</pre>
</body>
</html>
@DrewAPicture

This comment has been minimized.

Show comment
Hide comment
@DrewAPicture

DrewAPicture Jun 21, 2012

FYI, I got this to work using BitBucket pretty easily. They may have made allowances for POST requests in the last few months.

On BitBucket, went to the Repo > Admin > Services. Selected POST, dropped in my URL and saved it. Seems to be working as expected.

Thanks for the script, it makes my life a lot easier.

DrewAPicture commented Jun 21, 2012

FYI, I got this to work using BitBucket pretty easily. They may have made allowances for POST requests in the last few months.

On BitBucket, went to the Repo > Admin > Services. Selected POST, dropped in my URL and saved it. Seems to be working as expected.

Thanks for the script, it makes my life a lot easier.

@oodavid

This comment has been minimized.

Show comment
Hide comment
@oodavid

oodavid Jun 21, 2012

Glad it helped you out - the real trick for me was getting it so that Apache could play nicely with git...

Owner

oodavid commented Jun 21, 2012

Glad it helped you out - the real trick for me was getting it so that Apache could play nicely with git...

@nebriv

This comment has been minimized.

Show comment
Hide comment
@nebriv

nebriv Jul 31, 2012

Thanks! it works well for me on shared hosting, without keys!

nebriv commented Jul 31, 2012

Thanks! it works well for me on shared hosting, without keys!

@bgallagh3r

This comment has been minimized.

Show comment
Hide comment
@bgallagh3r

bgallagh3r Aug 21, 2012

Just a heads up. It would be smart to add git reset --hard HEAD in the commands before git pull. If for some reason your working directory is dirty (files changed, log files created etc) then the deploy will fail. Resetting the HEAD to the last commit will prevent a deploy failure.

bgallagh3r commented Aug 21, 2012

Just a heads up. It would be smart to add git reset --hard HEAD in the commands before git pull. If for some reason your working directory is dirty (files changed, log files created etc) then the deploy will fail. Resetting the HEAD to the last commit will prevent a deploy failure.

@mattbanks

This comment has been minimized.

Show comment
Hide comment
@mattbanks

mattbanks Aug 23, 2012

Do you worry about security of the deploy.php script? Is there any harm is someone hits that script, or anything malicious they can do?

mattbanks commented Aug 23, 2012

Do you worry about security of the deploy.php script? Is there any harm is someone hits that script, or anything malicious they can do?

@weblance2

This comment has been minimized.

Show comment
Hide comment
@weblance2

weblance2 Sep 7, 2012

got stuck here, any ideas on how to change permissions?

root@staging ~]# sudo -Hu apache ssh-keygen -t rsa # choose "no passphrase"
Generating public/private rsa key pair.
Enter file in which to save the key (/var/www/.ssh/id_rsa): githubkey
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
open githubkey failed: Permission denied.
Saving the key failed: githubkey.

weblance2 commented Sep 7, 2012

got stuck here, any ideas on how to change permissions?

root@staging ~]# sudo -Hu apache ssh-keygen -t rsa # choose "no passphrase"
Generating public/private rsa key pair.
Enter file in which to save the key (/var/www/.ssh/id_rsa): githubkey
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
open githubkey failed: Permission denied.
Saving the key failed: githubkey.

@weblance2

This comment has been minimized.

Show comment
Hide comment
@weblance2

weblance2 Sep 7, 2012

I created a key by skipping the create directory but now i get

[root@staging ~]# sudo -Hu apache git clone git@github.com:weblance2/primary-trunk.git /var/www/html/ fatal: destination path '/var/www/html' already exists and is not an empty directory.

weblance2 commented Sep 7, 2012

I created a key by skipping the create directory but now i get

[root@staging ~]# sudo -Hu apache git clone git@github.com:weblance2/primary-trunk.git /var/www/html/ fatal: destination path '/var/www/html' already exists and is not an empty directory.
@natxet

This comment has been minimized.

Show comment
Hide comment
@natxet

natxet Sep 29, 2012

as @mattbanks says, no security?

natxet commented Sep 29, 2012

as @mattbanks says, no security?

@jamesbrooks

This comment has been minimized.

Show comment
Hide comment
@jamesbrooks

jamesbrooks Oct 11, 2012

This might interest you: JamesBrooks/git-runner (with the git-runner-deploy gem).

jamesbrooks commented Oct 11, 2012

This might interest you: JamesBrooks/git-runner (with the git-runner-deploy gem).

@jamesbrooks

This comment has been minimized.

Show comment
Hide comment

jamesbrooks commented Oct 11, 2012

@jorijnsmit

This comment has been minimized.

Show comment
Hide comment
@jorijnsmit

jorijnsmit Nov 26, 2012

I got this working but am missing why I created SSH keys?

If I understand the script correctly anyone can hit the URL (http://server.com/deploy.php) and it will execute a git pull. How is the difference detected between the GitHub WebHook service and a random visitor or a web crawler?

I think I will do some more digging, I found https://github.com/Coppertino/github-webhook with a similar function but more advanced options like IP filtering and SSH/FTP support.

jorijnsmit commented Nov 26, 2012

I got this working but am missing why I created SSH keys?

If I understand the script correctly anyone can hit the URL (http://server.com/deploy.php) and it will execute a git pull. How is the difference detected between the GitHub WebHook service and a random visitor or a web crawler?

I think I will do some more digging, I found https://github.com/Coppertino/github-webhook with a similar function but more advanced options like IP filtering and SSH/FTP support.

@markomarkovic

This comment has been minimized.

Show comment
Hide comment
@markomarkovic

markomarkovic Jan 13, 2013

I've rewrote this gist and created a 'normal' repository for it. Check it out!

It features:

  • easy configuration
  • no need to create the clone on the server first, it's doing that automatically
  • basic security (through obscurity) so the script can't be triggered by anyone except the one who knows the secret
  • update the code using non-master branch
  • delete files that are no longer in the repository (DANGEROUS!)
  • ignore certain files/directories when updating
  • error detection: if any step prior to deploy fails, nothing is changed
  • stamp the deployed code version
  • backup the target prior to deploy

markomarkovic commented Jan 13, 2013

I've rewrote this gist and created a 'normal' repository for it. Check it out!

It features:

  • easy configuration
  • no need to create the clone on the server first, it's doing that automatically
  • basic security (through obscurity) so the script can't be triggered by anyone except the one who knows the secret
  • update the code using non-master branch
  • delete files that are no longer in the repository (DANGEROUS!)
  • ignore certain files/directories when updating
  • error detection: if any step prior to deploy fails, nothing is changed
  • stamp the deployed code version
  • backup the target prior to deploy
@zanematthew

This comment has been minimized.

Show comment
Hide comment
@zanematthew

zanematthew Jan 22, 2013

If this is all "local" why not just use native git? using a "working tree" and a "bare repo"?

https://gist.github.com/4597331
http://stackoverflow.com/questions/5283262/what-is-a-git-work-tree-why-have-i-never-needed-to-set-this-as-an-env-var-why

Also things like branch, and other useful into are already coming over in the payload from the github post-receive hook, https://help.github.com/articles/post-receive-hooks not sure why those are passed in via $_GET

zanematthew commented Jan 22, 2013

If this is all "local" why not just use native git? using a "working tree" and a "bare repo"?

https://gist.github.com/4597331
http://stackoverflow.com/questions/5283262/what-is-a-git-work-tree-why-have-i-never-needed-to-set-this-as-an-env-var-why

Also things like branch, and other useful into are already coming over in the payload from the github post-receive hook, https://help.github.com/articles/post-receive-hooks not sure why those are passed in via $_GET

@tabacitu

This comment has been minimized.

Show comment
Hide comment
@tabacitu

tabacitu Jan 29, 2013

Awesome, thanks! Just a heads-up, on Ubuntu my user was www-data, not apache.

tabacitu commented Jan 29, 2013

Awesome, thanks! Just a heads-up, on Ubuntu my user was www-data, not apache.

@DrewAPicture

This comment has been minimized.

Show comment
Hide comment
@DrewAPicture

DrewAPicture Feb 11, 2013

@mattbanks, @natxet: RE: security: Two things I usually do is to rename the script to {randomstring}.php, and modify it not to expose the username for all to see. Another option is to restrict referrer access to the script via htaccess.

DrewAPicture commented Feb 11, 2013

@mattbanks, @natxet: RE: security: Two things I usually do is to rename the script to {randomstring}.php, and modify it not to expose the username for all to see. Another option is to restrict referrer access to the script via htaccess.

@davemac

This comment has been minimized.

Show comment
Hide comment
@davemac

davemac Feb 15, 2013

I agree with @zanematthew. This method seems like overkill for what can be accomplished with a post-receive hook and a bare repo on the target server. Or am I missing something?

davemac commented Feb 15, 2013

I agree with @zanematthew. This method seems like overkill for what can be accomplished with a post-receive hook and a bare repo on the target server. Or am I missing something?

@anthonyringoet

This comment has been minimized.

Show comment
Hide comment
@anthonyringoet

anthonyringoet Feb 24, 2013

Already had ssh keys for my server because was pulling in changes manually. I'm using this in development and works perfect for me. Thanks!

anthonyringoet commented Feb 24, 2013

Already had ssh keys for my server because was pulling in changes manually. I'm using this in development and works perfect for me. Thanks!

@aguilarcarlos

This comment has been minimized.

Show comment
Hide comment
@aguilarcarlos

aguilarcarlos Oct 21, 2013

This is only when my server is on PHP really? At same I can't to build another for Python, it's cool this congrats. Still I not test this, but I think so it will function... thanks.

aguilarcarlos commented Oct 21, 2013

This is only when my server is on PHP really? At same I can't to build another for Python, it's cool this congrats. Still I not test this, but I think so it will function... thanks.

@vamsiikrishna

This comment has been minimized.

Show comment
Hide comment
@slouma2000

This comment has been minimized.

Show comment
Hide comment
@slouma2000

slouma2000 Jan 25, 2014

In my case I needed to change (etc/passwd) [Centos 6.2]

apache502:503:Apache server:/:/sbin/nologin
To
apache502:503:Apache server:/var/www:/sbin/nologin

slouma2000 commented Jan 25, 2014

In my case I needed to change (etc/passwd) [Centos 6.2]

apache502:503:Apache server:/:/sbin/nologin
To
apache502:503:Apache server:/var/www:/sbin/nologin

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Feb 2, 2014

Another PHP tool for the job. A bit more elaborate one.

https://github.com/Perennials/apache-git-sync-tool

ghost commented Feb 2, 2014

Another PHP tool for the job. A bit more elaborate one.

https://github.com/Perennials/apache-git-sync-tool

@drmikecrowe

This comment has been minimized.

Show comment
Hide comment
@drmikecrowe

drmikecrowe Apr 16, 2014

I've found and recommend this: http://magephp.com/

drmikecrowe commented Apr 16, 2014

I've found and recommend this: http://magephp.com/

@jimoconnell

This comment has been minimized.

Show comment
Hide comment
@jimoconnell

jimoconnell commented Jun 20, 2014

@zenware

This comment has been minimized.

Show comment
Hide comment
@zenware

zenware Aug 28, 2014

Your tag link to the deploy.php file is incorrect, it should be:
https://gist.github.com/oodavid/1809044#file-deploy-php

zenware commented Aug 28, 2014

Your tag link to the deploy.php file is incorrect, it should be:
https://gist.github.com/oodavid/1809044#file-deploy-php

@mukesh-rane

This comment has been minimized.

Show comment
Hide comment
@mukesh-rane

mukesh-rane Nov 13, 2014

I need help actually I did all the steps to
auto update
production updates from master branch
and
staging updates from staging branch
it works but only for production server ..

what i want is when I will push my changes to any working branch and merge it will staging branch my updates automatically goes to staging server and when I will merge my staging branch to master branch my updates automatically goes to production server

mukesh-rane commented Nov 13, 2014

I need help actually I did all the steps to
auto update
production updates from master branch
and
staging updates from staging branch
it works but only for production server ..

what i want is when I will push my changes to any working branch and merge it will staging branch my updates automatically goes to staging server and when I will merge my staging branch to master branch my updates automatically goes to production server

@MartinLyne

This comment has been minimized.

Show comment
Hide comment
@MartinLyne

MartinLyne Jan 28, 2015

if you change

$tmp = shell_exec($command);
to
$tmp = shell_exec($command.' 2>&1');

it will show error output too (handy when in wrong directory etc)

MartinLyne commented Jan 28, 2015

if you change

$tmp = shell_exec($command);
to
$tmp = shell_exec($command.' 2>&1');

it will show error output too (handy when in wrong directory etc)

@nickk80

This comment has been minimized.

Show comment
Hide comment
@nickk80

nickk80 Jan 31, 2015

I become every time this when I execute manually deploy.php:

On branch master

nothing to commit (working directory clean)

if I made changes to the master on github, the POST process and the deploy.php do nothing. ?? I'm to be desperate to do this! I kill all an go on your README 4 times and every time with the same problem.

nickk80 commented Jan 31, 2015

I become every time this when I execute manually deploy.php:

On branch master

nothing to commit (working directory clean)

if I made changes to the master on github, the POST process and the deploy.php do nothing. ?? I'm to be desperate to do this! I kill all an go on your README 4 times and every time with the same problem.

@sneakyimp

This comment has been minimized.

Show comment
Hide comment
@sneakyimp

sneakyimp Mar 12, 2015

Some security issues with this:

  • if the github repo is public, any clown in the world can co-opt your server into their botnet
  • Deploy.php doesn't even bother to validate that the incoming ping is actually from github. The approach described here fails to describe how one sets up a secret to sign the hook payload or to check that payload in PHP.
  • If this were implemented on a shared host, then pretty much anyone could take a peek at the ssh keys, both private and public.
  • Every single file in your web root can be written by Apache. On a shared host your files are at the mercy of anyone else on the server. Even if your machine is a single-purpose one, a single vulnerability in your code could easily compromise your entire web root.

sneakyimp commented Mar 12, 2015

Some security issues with this:

  • if the github repo is public, any clown in the world can co-opt your server into their botnet
  • Deploy.php doesn't even bother to validate that the incoming ping is actually from github. The approach described here fails to describe how one sets up a secret to sign the hook payload or to check that payload in PHP.
  • If this were implemented on a shared host, then pretty much anyone could take a peek at the ssh keys, both private and public.
  • Every single file in your web root can be written by Apache. On a shared host your files are at the mercy of anyone else on the server. Even if your machine is a single-purpose one, a single vulnerability in your code could easily compromise your entire web root.
@mssyogi

This comment has been minimized.

Show comment
Hide comment
@mssyogi

mssyogi May 21, 2015

I m unable to got working.

I hit the url with post hook as well as the browser but not get updated my repo.

http://www.awesomescreenshot.com/image/248530/29451649e6bfd2fd5da472d6915c9a82

mssyogi commented May 21, 2015

I m unable to got working.

I hit the url with post hook as well as the browser but not get updated my repo.

http://www.awesomescreenshot.com/image/248530/29451649e6bfd2fd5da472d6915c9a82

@noelboss

This comment has been minimized.

Show comment
Hide comment
@noelboss

noelboss Jun 23, 2015

I've found little tools to help deploy your code from Github or Gitlab so I created Deepl.io to handle Web-Hooks and call scripts to deploy on your own server.
This handles the JSON that's sent from github or gitlab and uses your own script to react. You can use your own PHP or shell scripts after receiving the pull notification...
Check it out: http://deepl.io

noelboss commented Jun 23, 2015

I've found little tools to help deploy your code from Github or Gitlab so I created Deepl.io to handle Web-Hooks and call scripts to deploy on your own server.
This handles the JSON that's sent from github or gitlab and uses your own script to react. You can use your own PHP or shell scripts after receiving the pull notification...
Check it out: http://deepl.io

@limzykenneth

This comment has been minimized.

Show comment
Hide comment
@limzykenneth

limzykenneth Jul 2, 2015

I modified the PHP script which should comply with Github's instruction on webhooks while also updated the instructions.

Deploy your site with git securely

limzykenneth commented Jul 2, 2015

I modified the PHP script which should comply with Github's instruction on webhooks while also updated the instructions.

Deploy your site with git securely

@dustindwyer

This comment has been minimized.

Show comment
Hide comment
@dustindwyer

dustindwyer Aug 10, 2015

If you have permission problems with git pull, but you can still git status, make sure your .git folders are owned by your apache git user. A git pull needs permission to modify the .git files.

Our solution:

chown -R www-data:www-data .git

from repository root directory

dustindwyer commented Aug 10, 2015

If you have permission problems with git pull, but you can still git status, make sure your .git folders are owned by your apache git user. A git pull needs permission to modify the .git files.

Our solution:

chown -R www-data:www-data .git

from repository root directory

@morales2k

This comment has been minimized.

Show comment
Hide comment
@morales2k

morales2k Aug 19, 2015

For "security" you could:

  1. add at the beggining of the file....
if (!isset($_GET['randomvar']) || $_GET['randomvar']!= 'random_value') {
        exit('Nope!');
}

and add ?randomvar=random_value to the webhook url when you create it.

  1. Rename the file to something random. (this - you should do it anyways)

  2. use .htaccess rules for that file - allow/deny and whitelist the ranges given by github or bitbucket for the webhooks... Not sure what they are for github, but for bitbucket it's this (table col that is labeled as Outbound (for hooks like POST))

That's about all that comes to mind....

Thanks for the script!

morales2k commented Aug 19, 2015

For "security" you could:

  1. add at the beggining of the file....
if (!isset($_GET['randomvar']) || $_GET['randomvar']!= 'random_value') {
        exit('Nope!');
}

and add ?randomvar=random_value to the webhook url when you create it.

  1. Rename the file to something random. (this - you should do it anyways)

  2. use .htaccess rules for that file - allow/deny and whitelist the ranges given by github or bitbucket for the webhooks... Not sure what they are for github, but for bitbucket it's this (table col that is labeled as Outbound (for hooks like POST))

That's about all that comes to mind....

Thanks for the script!

@adnanh

This comment has been minimized.

Show comment
Hide comment
@adnanh

adnanh Nov 21, 2015

Instead of a PHP script, one could use webhook and a shell script. For security, one can define trigger rules to include github payload signature check, etc...

adnanh commented Nov 21, 2015

Instead of a PHP script, one could use webhook and a shell script. For security, one can define trigger rules to include github payload signature check, etc...

@erm3nda

This comment has been minimized.

Show comment
Hide comment
@erm3nda

erm3nda Jan 21, 2016

Hum, i heard something that say it uses Github to deploy code. I'll use it, as it's perfect to sync the code.
What Im thinking now, is that i would not publish sensible PHP data into the Github public repo... I suspect that the user added Bitbucket due to it's private free repos 👍

Wich one of the suggested worked more like "out of the box"?
I prefer simpler than complex, just sync.

Regards.

erm3nda commented Jan 21, 2016

Hum, i heard something that say it uses Github to deploy code. I'll use it, as it's perfect to sync the code.
What Im thinking now, is that i would not publish sensible PHP data into the Github public repo... I suspect that the user added Bitbucket due to it's private free repos 👍

Wich one of the suggested worked more like "out of the box"?
I prefer simpler than complex, just sync.

Regards.

@robbiegod

This comment has been minimized.

Show comment
Hide comment
@robbiegod

robbiegod Jun 8, 2016

Looks interesting. I noticed a small problem in your Gist. The anchor link to "See deploy.php" is incorrect. The anchor is currently #file_deploy.php, but actually should be #file-deploy.php.

robbiegod commented Jun 8, 2016

Looks interesting. I noticed a small problem in your Gist. The anchor link to "See deploy.php" is incorrect. The anchor is currently #file_deploy.php, but actually should be #file-deploy.php.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 13, 2016

Hi All,

Thanks in advance.
I am new to jenkin and CI. My question is below.
My project is in Angular, node and express js and SCM is git. So i want to automate the build and deployment via Jenkins, so please help me on this.
As of now i have configured the Gitub plugin in Jenkins which get trigger when we make any commit. I need the script which help to deploy the changes to Windows Web server.

Note : I am working on Windows.

ghost commented Jun 13, 2016

Hi All,

Thanks in advance.
I am new to jenkin and CI. My question is below.
My project is in Angular, node and express js and SCM is git. So i want to automate the build and deployment via Jenkins, so please help me on this.
As of now i have configured the Gitub plugin in Jenkins which get trigger when we make any commit. I need the script which help to deploy the changes to Windows Web server.

Note : I am working on Windows.

@jdmagic21

This comment has been minimized.

Show comment
Hide comment
@jdmagic21

jdmagic21 Jul 8, 2016

I like your script idea but I agree with @bgallagh3r . If something happens were a file is deleted, a git pull is not bring this file back. You have to use a git reset.

jdmagic21 commented Jul 8, 2016

I like your script idea but I agree with @bgallagh3r . If something happens were a file is deleted, a git pull is not bring this file back. You have to use a git reset.

@davidpMFA

This comment has been minimized.

Show comment
Hide comment
@davidpMFA

davidpMFA Jul 13, 2016

The shell_exec command on the git pull doesn't do anything for me. All other git commands run fine.

davidpMFA commented Jul 13, 2016

The shell_exec command on the git pull doesn't do anything for me. All other git commands run fine.

@jestherthejoker

This comment has been minimized.

Show comment
Hide comment
@jestherthejoker

jestherthejoker Jul 19, 2016

Hey, I've successfully created the and deploy the initial (private repo)repository, but after all while trying to git pull the ssh key was rejected. can you help me with this? machine is running on Ubuntu 14

jestherthejoker commented Jul 19, 2016

Hey, I've successfully created the and deploy the initial (private repo)repository, but after all while trying to git pull the ssh key was rejected. can you help me with this? machine is running on Ubuntu 14

@tareq1988

This comment has been minimized.

Show comment
Hide comment
@tareq1988

tareq1988 Jul 28, 2016

Apologize if it seems a promotion: but made this tool: gitpull as a hosted service.

tareq1988 commented Jul 28, 2016

Apologize if it seems a promotion: but made this tool: gitpull as a hosted service.

@avramovic

This comment has been minimized.

Show comment
Hide comment
@avramovic

avramovic Aug 14, 2016

@tareq1988 This seems nice but you should add an option to execute custom commands before/after git pull. For example if I want to migrate the database after git pull. Also, add some feedback form so you can get ideas such as this one from your users.

avramovic commented Aug 14, 2016

@tareq1988 This seems nice but you should add an option to execute custom commands before/after git pull. For example if I want to migrate the database after git pull. Also, add some feedback form so you can get ideas such as this one from your users.

@xgqfrms-GitHub

This comment has been minimized.

Show comment
Hide comment
@xgqfrms-GitHub

xgqfrms-GitHub commented Sep 20, 2016

Not Too Bad!

@burningbaal

This comment has been minimized.

Show comment
Hide comment
@burningbaal

burningbaal Oct 30, 2016

the link for setting up service hook (https://github.com/oodavid/server.com/admin/hooks) doesn't work, 404

burningbaal commented Oct 30, 2016

the link for setting up service hook (https://github.com/oodavid/server.com/admin/hooks) doesn't work, 404

@benyanke

This comment has been minimized.

Show comment
Hide comment
@benyanke

benyanke Feb 16, 2017

I would suggest optionally adding 'git reset --hard,' to ensure the pull happens correctly. If you're using the git workflow properly, it shouldn't matter if local changes are dumped, because all the important files should be in the repo anyways.

benyanke commented Feb 16, 2017

I would suggest optionally adding 'git reset --hard,' to ensure the pull happens correctly. If you're using the git workflow properly, it shouldn't matter if local changes are dumped, because all the important files should be in the repo anyways.

@geobde

This comment has been minimized.

Show comment
Hide comment
@geobde

geobde Feb 16, 2017

hi guys i try this method with gitlab and dont work you have any ideas?

geobde commented Feb 16, 2017

hi guys i try this method with gitlab and dont work you have any ideas?

@webassic15

This comment has been minimized.

Show comment
Hide comment
@webassic15

webassic15 Mar 30, 2017

Hi, i am using Ubuntu OS, i cloned repo from bitbucket on local env & set the ssh key access. if i tried to pull / push via terminal then all is working fine. but if i run that script on my local then getting a error : Host key verification failed.
fatal: Could not read from remote repository.

Also whoaim command showing a user - "www-data" but i am using "web-dev" user on my system.

Please help to resolve this issue.

webassic15 commented Mar 30, 2017

Hi, i am using Ubuntu OS, i cloned repo from bitbucket on local env & set the ssh key access. if i tried to pull / push via terminal then all is working fine. but if i run that script on my local then getting a error : Host key verification failed.
fatal: Could not read from remote repository.

Also whoaim command showing a user - "www-data" but i am using "web-dev" user on my system.

Please help to resolve this issue.

@agrublev

This comment has been minimized.

Show comment
Hide comment
@agrublev

agrublev Apr 7, 2017

For those interested on ubuntu this is what you have to do (sad nobody added it yet, took me an hour)

Edit /etc/sudoers to add
www-data ALL = NOPASSWD: /usr/bin/git
Then add to the git pull in deploy.php
'sudo git pull'

Without this I could not pull.

agrublev commented Apr 7, 2017

For those interested on ubuntu this is what you have to do (sad nobody added it yet, took me an hour)

Edit /etc/sudoers to add
www-data ALL = NOPASSWD: /usr/bin/git
Then add to the git pull in deploy.php
'sudo git pull'

Without this I could not pull.

@kiran-nani

This comment has been minimized.

Show comment
Hide comment
@kiran-nani

kiran-nani Apr 10, 2017

I have Nginx server, how can I do that..

kiran-nani commented Apr 10, 2017

I have Nginx server, how can I do that..

@adrianogoncalves

This comment has been minimized.

Show comment
Hide comment
@adrianogoncalves

adrianogoncalves Apr 22, 2017

Great script! It's running like a charm with Bitbucket. Thank you for the help!

adrianogoncalves commented Apr 22, 2017

Great script! It's running like a charm with Bitbucket. Thank you for the help!

@xenu256

This comment has been minimized.

Show comment
Hide comment
@xenu256

xenu256 Jun 5, 2017

Isn't it better to name things more appropriately?

https://github.com/[username]/[project]/admin/hooks

oinstead of:

https://github.com/oodavid/server.com/admin/hooks

xenu256 commented Jun 5, 2017

Isn't it better to name things more appropriately?

https://github.com/[username]/[project]/admin/hooks

oinstead of:

https://github.com/oodavid/server.com/admin/hooks
@Kiodaddy

This comment has been minimized.

Show comment
Hide comment
@Kiodaddy

Kiodaddy Jun 14, 2017

Great script its working fine.

Kiodaddy commented Jun 14, 2017

Great script its working fine.

@scriptburn

This comment has been minimized.

Show comment
Hide comment
@scriptburn

scriptburn Jun 29, 2017

why not use this https://github.com/scriptburn/git-auto-deploy and save typing all these commands?

scriptburn commented Jun 29, 2017

why not use this https://github.com/scriptburn/git-auto-deploy and save typing all these commands?

@jackdeguest

This comment has been minimized.

Show comment
Hide comment
@jackdeguest

jackdeguest Aug 29, 2017

If the purpose is to publish a git repository to a live server, then just cut the middle man.
This explains how to use git to publish from the local host to the remote server directly and using different possible branch like beta, live, etc to which one can associate sub domain for validation for example.
https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps

jackdeguest commented Aug 29, 2017

If the purpose is to publish a git repository to a live server, then just cut the middle man.
This explains how to use git to publish from the local host to the remote server directly and using different possible branch like beta, live, etc to which one can associate sub domain for validation for example.
https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps

@adnanh

This comment has been minimized.

Show comment
Hide comment
@mckaycr

This comment has been minimized.

Show comment
Hide comment
@mckaycr

mckaycr Sep 25, 2017

This was easy to integrate, thanks. I use 1and1 shared webservice (or whatever its call). Bottomline it doesn't support ssh keys, only passwords unless I upgrade to the next package. Upgrading is probably not an option for my non-profit group. Is there a way to implement this so that the server doesn't need a key to pull changes from my (custom) gitlab server?

mckaycr commented Sep 25, 2017

This was easy to integrate, thanks. I use 1and1 shared webservice (or whatever its call). Bottomline it doesn't support ssh keys, only passwords unless I upgrade to the next package. Upgrading is probably not an option for my non-profit group. Is there a way to implement this so that the server doesn't need a key to pull changes from my (custom) gitlab server?

@nate-fr

This comment has been minimized.

Show comment
Hide comment
@nate-fr

nate-fr Oct 23, 2017

This Script is vulnerable. DO NOT USE IT.

Exploitation: https://www.exploit-db.com/ghdb/4593/

nate-fr commented Oct 23, 2017

This Script is vulnerable. DO NOT USE IT.

Exploitation: https://www.exploit-db.com/ghdb/4593/

@pdulapalli

This comment has been minimized.

Show comment
Hide comment
@pdulapalli

pdulapalli Jan 3, 2018

Quick question, is this script easily adapted for Nginx servers?

pdulapalli commented Jan 3, 2018

Quick question, is this script easily adapted for Nginx servers?

@waleCloud

This comment has been minimized.

Show comment
Hide comment
@waleCloud

waleCloud Jan 9, 2018

Quick question please i don't understand the URL to your deployment script - http://server.com/deploy.php

What's my URL to the deploy script?

waleCloud commented Jan 9, 2018

Quick question please i don't understand the URL to your deployment script - http://server.com/deploy.php

What's my URL to the deploy script?

@udezekene

This comment has been minimized.

Show comment
Hide comment
@udezekene

udezekene Mar 4, 2018

@waleCloud. You are supposed to upload the deploy.php script included here to your server. http://server.com/deploy.php represents the path to the deploy.php file on your own server/domain

udezekene commented Mar 4, 2018

@waleCloud. You are supposed to upload the deploy.php script included here to your server. http://server.com/deploy.php represents the path to the deploy.php file on your own server/domain

@olayinkaokewale

This comment has been minimized.

Show comment
Hide comment
@olayinkaokewale

olayinkaokewale Aug 3, 2018

This doesn't work if safe_mode is disabled

olayinkaokewale commented Aug 3, 2018

This doesn't work if safe_mode is disabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment