{"id":1135,"date":"2015-07-01T22:01:32","date_gmt":"2015-07-01T20:01:32","guid":{"rendered":"http:\/\/www.robinglauser.ch\/blog\/?p=1135"},"modified":"2015-09-17T21:30:42","modified_gmt":"2015-09-17T19:30:42","slug":"use-github-webhooks-to-automatically-push-your-changes-to-a-webserver","status":"publish","type":"post","link":"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/","title":{"rendered":"Use Github Webhooks to automatically push your changes to a webserver."},"content":{"rendered":"<p>I&#8217;ve installed a little Github Webhook for my <a href=\"https:\/\/github.com\/nahakiole\/robinglauser.ch\" target=\"_blank\">portfolio repository<\/a>\u00a0so whenever I make changes to the repository they automatically get deployed to my webserver.<\/p>\n<p>For this little trick to work you have to have a git client installed on your webserver. Also the shell_exec php function has to be active so we can run the git pull command from php.<\/p>\n<p>First we have to clone the repository on your server in the directory where the website should be.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\"> git clone https:\/\/github.com\/nahakiole\/robinglauser.ch .<\/pre>\n<p>Then we have to create two files, one php file as the webhook and a shell script which resets the repository and pulls the latest changes.<\/p>\n<p><strong>push (Shell script)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\"> git reset --hard HEAD\r\ngit pull\r\ngit submodule update --init --recursive<\/pre>\n<p><strong>githook.php (Githook :D)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\"> &lt;?php\r\n\r\nshell_exec( 'chmod +x push' );\r\nshell_exec( '.\/push' );\r\necho 'It works!';<\/pre>\n<p>After you&#8217;ve created the two files you can test them by calling the githook.php file from your webserver, this should then reset the repository and pull in the latest changes.<\/p>\n<p>If this works until here we can add the githook in our repository under &#8220;Settings&#8221;, &#8220;Webhooks and Services&#8221; and then &#8220;Add webhook&#8221;<\/p>\n<p>In the field &#8220;Payload URL&#8221; you can then add the url to your githook.php file. I&#8217;d recommend to change the &#8220;Content type&#8221; to &#8220;application\/x-www-form-urlencoded&#8221;.<\/p>\n<p>The rest of the options can\u00a0be left to the defaults.<\/p>\n<p>Now if you push changes to the repository or even make changes directly over the webinterface they will get updated on your webserver automatically without the use of any other service.<\/p>\n<p>This is of course only usable for small static websites, although it could be extended to run more commands in the push shellscript.<\/p>\n<p>If you have any questions or if you&#8217;ve run into any issues while following this tutorial, please leave a comment and I will get back to you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">I&#8217;ve installed a little Github Webhook for my portfolio repository\u00a0so whenever I make changes to the repository they automatically get deployed to my webserver. For this little trick to work you have to have a git client installed on your webserver. Also the shell_exec php function has to be active so we can run the git pull command from php. &#8230; <a class=\"read-more\" href=\"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[45,5],"tags":[],"class_list":["post-1135","post","type-post","status-publish","format-standard","hentry","category-development","category-fresh"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Use Github Webhooks to automatically push your changes to a webserver. - Robin Glauser<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Use Github Webhooks to automatically push your changes to a webserver. - Robin Glauser\" \/>\n<meta property=\"og:description\" content=\"I&#8217;ve installed a little Github Webhook for my portfolio repository\u00a0so whenever I make changes to the repository they automatically get deployed to my webserver. For this little trick to work you have to have a git client installed on your webserver. Also the shell_exec php function has to be active so we can run the git pull command from php. ... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/\" \/>\n<meta property=\"og:site_name\" content=\"Robin Glauser\" \/>\n<meta property=\"article:published_time\" content=\"2015-07-01T20:01:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-09-17T19:30:42+00:00\" \/>\n<meta name=\"author\" content=\"Robin Glauser\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@robinglauser\" \/>\n<meta name=\"twitter:site\" content=\"@robinglauser\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Robin Glauser\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/\"},\"author\":{\"name\":\"Robin Glauser\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19\"},\"headline\":\"Use Github Webhooks to automatically push your changes to a webserver.\",\"datePublished\":\"2015-07-01T20:01:32+00:00\",\"dateModified\":\"2015-09-17T19:30:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/\"},\"wordCount\":337,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19\"},\"articleSection\":[\"Development\",\"Fresh\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/\",\"url\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/\",\"name\":\"Use Github Webhooks to automatically push your changes to a webserver. - Robin Glauser\",\"isPartOf\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#website\"},\"datePublished\":\"2015-07-01T20:01:32+00:00\",\"dateModified\":\"2015-09-17T19:30:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.robinglauser.ch\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Use Github Webhooks to automatically push your changes to a webserver.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#website\",\"url\":\"https:\/\/www.robinglauser.ch\/blog\/\",\"name\":\"Robin Glauser\",\"description\":\"My Blog about Development, Design and my random thoughts.\",\"publisher\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.robinglauser.ch\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19\",\"name\":\"Robin Glauser\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg\",\"url\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg\",\"contentUrl\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg\",\"width\":800,\"height\":530,\"caption\":\"Robin Glauser\"},\"logo\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg\"},\"description\":\"I'm a web developer.\",\"sameAs\":[\"https:\/\/www.robinglauser.ch\",\"https:\/\/www.instagram.com\/robinglauser\/\",\"https:\/\/x.com\/robinglauser\"],\"url\":\"https:\/\/www.robinglauser.ch\/blog\/author\/robin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Use Github Webhooks to automatically push your changes to a webserver. - Robin Glauser","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/","og_locale":"en_US","og_type":"article","og_title":"Use Github Webhooks to automatically push your changes to a webserver. - Robin Glauser","og_description":"I&#8217;ve installed a little Github Webhook for my portfolio repository\u00a0so whenever I make changes to the repository they automatically get deployed to my webserver. For this little trick to work you have to have a git client installed on your webserver. Also the shell_exec php function has to be active so we can run the git pull command from php. ... Read More","og_url":"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/","og_site_name":"Robin Glauser","article_published_time":"2015-07-01T20:01:32+00:00","article_modified_time":"2015-09-17T19:30:42+00:00","author":"Robin Glauser","twitter_card":"summary_large_image","twitter_creator":"@robinglauser","twitter_site":"@robinglauser","twitter_misc":{"Written by":"Robin Glauser","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/#article","isPartOf":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/"},"author":{"name":"Robin Glauser","@id":"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19"},"headline":"Use Github Webhooks to automatically push your changes to a webserver.","datePublished":"2015-07-01T20:01:32+00:00","dateModified":"2015-09-17T19:30:42+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/"},"wordCount":337,"commentCount":0,"publisher":{"@id":"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19"},"articleSection":["Development","Fresh"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/","url":"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/","name":"Use Github Webhooks to automatically push your changes to a webserver. - Robin Glauser","isPartOf":{"@id":"https:\/\/www.robinglauser.ch\/blog\/#website"},"datePublished":"2015-07-01T20:01:32+00:00","dateModified":"2015-09-17T19:30:42+00:00","breadcrumb":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/07\/01\/use-github-webhooks-to-automatically-push-your-changes-to-a-webserver\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robinglauser.ch\/blog\/"},{"@type":"ListItem","position":2,"name":"Use Github Webhooks to automatically push your changes to a webserver."}]},{"@type":"WebSite","@id":"https:\/\/www.robinglauser.ch\/blog\/#website","url":"https:\/\/www.robinglauser.ch\/blog\/","name":"Robin Glauser","description":"My Blog about Development, Design and my random thoughts.","publisher":{"@id":"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robinglauser.ch\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19","name":"Robin Glauser","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg","url":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg","contentUrl":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg","width":800,"height":530,"caption":"Robin Glauser"},"logo":{"@id":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg"},"description":"I'm a web developer.","sameAs":["https:\/\/www.robinglauser.ch","https:\/\/www.instagram.com\/robinglauser\/","https:\/\/x.com\/robinglauser"],"url":"https:\/\/www.robinglauser.ch\/blog\/author\/robin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/posts\/1135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/comments?post=1135"}],"version-history":[{"count":9,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/posts\/1135\/revisions"}],"predecessor-version":[{"id":1156,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/posts\/1135\/revisions\/1156"}],"wp:attachment":[{"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/media?parent=1135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/categories?post=1135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/tags?post=1135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}