Github webhook PHP script for automated git pull on linux server

If you have a php website repository on Github and want to immediately deploy it to your server directory whenever you push to that repository from anywhere, then you should consider setting up a webhook in Github that will be triggered whenever anything is pushed to the repository. The webhook is just a php script that will be executed on your server and it will perform a git pull on the repository cloned on your server. You can clone this repository in a webroot so that whenever you push, your changes are immediately reflected on the server.
Following is a php script I use to automate this task. Several things to note before using this script :

  • Script assumes that your Github repository is cloned on your server
  • You may need to install sendmail on linux server since the script sends an email report to you whenever a hook is triggered
  • You need to give read/write access to the server directory where git pull will take place to the user your apache (or any other) server is running as (usually ‘daemon’ on ubuntu server or ‘www’)
  • You need to Setup a ‘Secret’ which is like a passphrase by going to Github–>Your Repo–>Settings–>Webhook. You will also need to configure this secret in the php script or as an environment variable on your server. This is used to authenticate and validate requests from Github and deny any other malicious attempts at triggering your webhook endpoint script

Without further ado, here is the php script code and the corresponding configuration file. Make sure to place the configuration file outside of your webroot so that it is not accessible from outside.

 

Github webhook PHP script :

<?php
/*
 * PHP endpoint for github webhook
 *
 * original: https://help.github.com/articles/post-receive-hooks
 * modified by dynamicguru.com
 */

 // Configuration :
$error_email = "youremail@domain.com"; // The email address to send report to in case an error occurs while executing this script
$php_script_information = "Email triggered by : ".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$script_email_name = "Github webhook pull script";  // The name of sender used in email reports that will be sent

function run() {
    global $php_script_information;
    global $script_email_name;    
    
    // Configuration :
    $secret = "SECRET_PASSPHRASE";  // The secret set in github->repo->Settings->Webhooks. You should ideally read this from $_ENV (set it using 'export' command on a linux machine)
    $commandsToRun = 'cd /path/to/server/repository; git pull';
    $config_filename = '/path/to/config.json';  // path to the configuration file, recommended to place it outside your website root (htdocs/www etc)
    
    
    if (!file_exists($config_filename)) {
        throw new Exception("Could not find ".$config_filename);    // raise an Exception if configuration file is not found
    }

    $config = json_decode(file_get_contents($config_filename), true);   // parse the json configuration



    $postBody = $_POST['payload'];  // the payload sent by github
    $payload = json_decode($postBody);  // decode the payload sent by github, see https://developer.github.com/webhooks/#payloads
    $headerSignature = $_SERVER['HTTP_X_HUB_SIGNATURE'];    // the signature/hash of request sent by github
    $signature = 'sha1=' . hash_hmac('sha1', file_get_contents('php://input'), $secret);    // compute the signature/hash of request

    if (isset($config['email'])) {  // if an email address is set in config file, we'll send the report to that address
        $headers = 'From: '.$script_email_name."<".$config['email']['from'].">\r\n";
        $headers .= 'CC: ' . $payload->pusher->email . "\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";  // HTML email
    }


    if (hash_equals($signature, $headerSignature)) {    // validate if this is a legit request from Github
        foreach ($config['endpoints'] as $endpoint) {
            
            if ($payload->repository->url == 'https://github.com/' . $endpoint['repo']
                && $payload->ref == 'refs/heads/' . $endpoint['branch']) {  // check if the push came from the right repository and branch
                // execute pull script, and record its output
                ob_start();
                
                passthru($commandsToRun); // the commands to run (navigate to your directory, pull from git etc)
                $output = ob_get_contents();    // get output of commands executed
                
                
                if (isset($config['email'])) { // prepare and send the notification email
                    // build the email body, you can add more details to this by referring to the json payload that is sent by github (https://developer.github.com/webhooks/#payloads)
                    $body = 'Request by Github from IP : '.$_SERVER['REMOTE_ADDR']
                    .'<p>User <a href="https://github.com/'. $payload->pusher->name .'">@' . $payload->pusher->name . '</a>'
                    . ' has pushed to ' . $payload->repository->url
                    . ' and consequently, ' . $endpoint['action']
                    . '.</p>';
                    $body .= '<p>Here\'s a brief list of changes:</p>';
                    $body .= '<ul>';
                    foreach ($payload->commits as $commit) {    // add each commit information
                        $body .= '<li>'.$commit->message.'<br />';
                        $body .= '<small style="color:#777"> Added: <b>'.count($commit->added)
                            .'</b> &nbsp; Modified: <b>'.count($commit->modified)
                            .'</b> &nbsp; Removed: <b>'.count($commit->removed)
                            .'</b> &nbsp; <a href="' . $commit->url
                            . '">...</a></small></li>';
                    }
                    $body .= '</ul>';
                    $body .= '<p>Pull script output : </p>';
                    $body .= $output. ' ';
                    $body .= $php_script_information;
                    mail($config['email']['to'], $endpoint['action'], $body, $headers); // send out the email
                }
                return true;
            }
        }
    } else {
        throw new Exception("This does not appear to be a valid request from Github.\nComputed signature was : ".$signature."\n  Github sent : ".$headerSignature." ");
    }
}




try {
    if (!isset($_POST['payload'])) {
        echo "I do nothing when loaded directly :)";
    } else {
        run();
    }
} catch ( Exception $e ) {
    $msg = $e->getMessage();
    mail($error_email,  // the address to send email to
         'Error occured while executing Github webhook endpoint',   // email subject
         $msg."\r\n".$php_script_information,   // the email body
         "From: ".$script_email_name."<script@yourdomain.com>\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=ISO-8859-1\r\n"    // headers
    );
}

Configuration json file :

{
    "email": {
        "from": "script@yourdomain.com",
        "to": "you@yourdomain.com"
    },
    "endpoints": [
        {
            "repo": "github-username/repository-name",
            "branch": "master",
            "action": "Something changed on the server"
        }
    ]
}



For more information, see https://developer.github.com/webhooks/

 

Do more with the browser’s in-built JavaScript console

Most would be familiar with the god-send console.log() used for debugging web applications.
Many modern browsers also implement several other handy console functions for when you need to do a little extra with the console. These functions are :

  • console.info()
  • console.warn()
  • console.error()
  • console.debug()

Here is how they look in Chrome’s console :

The different flavors of console logging

The different flavors of console logging

Common use-cases for these include helpful messages in development code or libraries and anything else you can think of.

Chrome’s Developer Tools also supports a nifty console.memory object which can help debug performance bottlenecks in your front-end applications.

 

Understanding Your Game Options at an Online Casino

If you are new to online casino gaming, you may feel overwhelmed when you first visit an online casino. Some of the top online casinos offer hundreds of unique games, with a range of game types and styles available for players to choose from. It is important to understand the different casino games for UK players that are available when you play online, in order to help you make an informed decision of which games are best for you to play.

 

Table Games

There are a range of table games available, including dice games and card games. The most popular of these games are blackjack, baccarat, roulette and table poker. There are entire suites of these games available with the possibility to find more than ten variations of each at a single online casino.

Slots

Slots are the most popular casino games available online. Top online casinos may offer hundreds of unique slot titles and these come in different variations. The most common types of slot games are classic games and video slot games. Video slots tend to have more modern graphics and a range of bonus features, although some lack bonus features, while some classic games do have basic bonus features. Slots come in a range of themes with unique graphics and animations to suit all types of preferences.

Video Poker

Video poker is a simplified poker-type game played on a slot-like machine. There are large suites of these games available at any online casino with a range of variations to choose from. These include single hand and multi-hand games with up to 100 hands available.

Jackpot Games

Jackpot games are exciting as they offer growing progressive jackpots. Progressive jackpots are most common in slot games, but most casinos offer progressive jackpot table games as well. There are specific requirements for being eligible for the progressive jackpot in a game so make sure you are aware of the rules before you begin.

Others

  • Scratch cards – These traditionally land-based instant win games are becoming more popular at online casinos and some casinos offer a range of games to choose from.
  • Keno – This lottery-style game is ideal for players who enjoy the thrill of a lottery with the chance to win a huge payout off a small bet.
  • Bingo – While there are dedicated bingo sites, some online casinos offer a few bingo variations for players to enjoy.
  • Live dealer games – These are a growing category of games which stream live dealers in action, giving you a land-based casino experience from home. Typically, you can enjoy live blackjack, roulette and baccarat, although some casinos offer other variations as well.

 

Knowing your options will help you choose the game that will most appeal to you for its style, graphics and bonus features. With so many choices, there is something for everyone.

 

Latest Barcelona GSMA conference gaming developments

The GSMA Congress has always done a great job at bringing together the top talents and stakeholders in the communication industry. If you are concerned with catching up with the latest trends in the mobile industry, then GSMA Mobile World Congress is one such event you should set your eyes on. This year’s event took place between February 27 and March 2nd. As always, the conference attracted some of the brilliant brains in the mobile, finance, automotive, technology and even healthcare industries.

But as far as this year’s event is concerned, it appears that online gaming is gaining significance day by day since new devices are being introduced to push the agenda even furthermore. Since this event serves as a launching pad for the year’s big smart phone companies, attendees still had to treat their eyes and ears to some great news pertaining to the re-launch of the Nokia Brand, the Blackberry as well as the rise of AI or Artificial Intelligence.

The re-launch of Nokia and how this is related to the latest gaming development

We all know that Steve Jobs was a factor to blame for the fall of Nokia since he introduced iPhone and an open-minded app store that would see this brand sliding into oblivion.

The brand was sold to Microsoft which ended up killing it altogether—although it preserved some brand rights which would later see Microsoft licensing a Finish startup called HMD to revive the brand.

We actually learned from this year’s Barcelona GSMA congress that Nokia was being re-launched in two variants with displays measuring 5.2’’ and 5.5’’ respectively. The phones will be running Google’s famous Android platform, and this is in line with the overall agenda of internet gaming.

Through introducing a sizeable display in a Nokia device and also letting it run the latest Android version, casino companies like Royal Vegas online casino will be pleased to welcome new users as more customers are expected to get these Nokia devices at a cheaper price. With better graphic engines and large displays to enjoy, Nokia believes that they will recapture the market again.

Blackberry making a come-back in a big way

If you thought the iconic Blackberry device was strictly meant for business purposes (at least before the brand died), then you ought to know that the new Blackberry Key One phone will accommodate intense gaming as well.

Having been licensed to a Chinese company called TCL Communications, most people are of the opinion that the phone will compete better with rivals this time round. For sure, the phone has a nice blend of Blackberry’s iconic features with those of Android phones.

While people were quick to point out that the display (4.5’’) is a little smaller compared to that of iPhone Plus or Google Pixel XL, the company insists that the screen is actually big enough when the virtual keyboard is turned on. Now, this means that you can finally play games using a virtual keyboard (as opposed to touching and swiping) on a Blackberry. And to favor the gaming industry, Blackberry will be selling the device for $100 less in the US market (when compared to Apple and Samsung devices).

Basically, this year’s World Mobile Congress made major strides in mobile device technology in relation to gaming. They even talked about AI, a concept that can be applied in almost all facets of the market. In fact, there are talks that AI is now being tested in relation to gaming. If things go well, then we could possibly see a scenario where this technology will be used in platforms such as Royal Vegas Online Casino to benefit players.

 

How to create game content when you have NO drawing skills

Can you create a gaming website if you only no code? The answer is yes!

So, you are sitting on your computer playing your favorite game when it occurs to you that you could make a better version of it. Perhaps you want bigger guns, more adversaries, a flying monkey, who knows? All you know is that you have the coding knowledge to make the best gaming website ever. But then it occurs to you, you have absolutely no drawing and 3D skills whatsoever. You stickmen even look bad. Should you abandon your pursuits of the best gaming site ever, or is there a solution? The answer is yes, there are solutions and you can create a great gaming website if you only know code.

You will need to have game code knowledge

Unless you are planning on spending a ton of money on hiring someone to create the game, you will need to understand the basic language of the gaming software which is available. Game software includes Unreal, CryEngine, and Unity. Granted, there are other platforms out there, but for the most part this is it. If you are planning on having your game on a mobile device, and let us be realistic if you want your game played you do, then you will need to know the standards for either IOS or Android games.

Create a storyboard

For this part of the process, I would advise that you hire a freelancer to do the work for you. Write out a brief listing the progression of the game. Be sure to include any 3D models or 3D Characters you intend to have in the game. This will allow for the storyboard artist to better draft out, visually, key points in the game. Be specific so that you do not have multiple revisions. For example, you would not want to state “I want to create a war game with tanks” as this is too ambiguous. Instead you would need to state something along the lines of “I am creating a WWII first person shooter game which will have the ability for the players to ride in and control the tanks as they siege key historical battle points.”

When picking out your storyboard artist, check their feedback, look at the examples of their work (it does no good to hire someone that draws as poorly as you do), and negotiate the number of revisions. Once you have your storyboard nailed down, then you can move on to the actual creation.

Acquire your elements

It is not cheating to purchase 3D Characters and 3D models for your game. In fact, it is rather smart as it optimizes the time that you will need to spend on visual development. When looking for your 3D content, look for models which are 3D and not 2D. With the advancements in the shading and rendering of 3D objects, even if you are trying to get a 2D look you can do so with 3D. However, 2D will always remain in 2D format. To explain better, if you need to rotate a character 10 degrees to make it look better in the game, a 3D model can easily do this. However, in 2D the character would need to be redrawn.

3D elements should be low poly for your game. For those which do not know about modeling (and if you cannot draw the odds are that you have not done 3D modeling), this means that the data for the model has been reduced by making the model have less visual surfaces. As a result, the game loads and runs faster. High poly characters may look better, but for gaming purposes they are useless.

Get to coding

And now is the moment that you have been waiting for, coding. Since you already have a firm grasp of how to code, the last step is using your coding knowledge to make the 3D models interact with the other elements in the game. Here is where your resolution outputs, your collisions, power-ups, and effects will come into play. Yes, you have purchased the elements and they are ready to go, but now you have to make them do something. If coding does not cover all the animation and interactions you need, you might have to go into the 3D software development program, such as 3ds max and render out some animation sets.

Be sure that once your coding is done that you do Alpha and Beta testing on your site before you go live or submit it to Apple or Google. I would highly recommend that you use a debugger program to find any potential errors in your coding.

What to do next?

Well, you have done it. You have created a game without any visual skills at all and I works great. The only thing that remains is to play it, sell it, and think of your next big idea for your gaming site.

 

Key considerations for your gaming website

Gaming Website

The video gaming revolution of the 21st century has brought many challenges to the budding web developer. As well as the constantly expanding range of platforms, web browsers and scripting software, there’s also a new generation of gamers who are evermore sensitive to any gaming site that falls short of the heightened expectations.

So what can you do to ensure a failsafe gaming experience? Here are a few tips and examples from the likes of action RPG games to even online casino titles that show the obstacles that must be overcome to give you a gaming site to truly be proud of.

The Ninja Kiwi games developers have had a proven track record of successes in the online gaming sphere thanks to their aesthetically-simple, yet tactically complex series of games such as Fortress Destroyer.

As well as being a popular mobile gaming app for iOS and Android devices, the game has also developed a new lease of life as an online browser-based game. However, although it can easily be played on Safari and Firefox browser, it is still inexplicably unable to function on Google Chrome which will undoubtedly limit its overall effectiveness.

Being able to cater towards a wide variety of gaming platforms is obviously a time consuming affair, but with App Stores making it relatively easy for even the smallest indie title to reach a global audience, it’s definitely a step worth taking.

A good example would be Mr Smith Casino who, as well as a casino app, have also ensured that their website has an easily browsable selection of titles complete with atmospheric audio so that gamers can easily see which gambling game can provide the best jackpot from the convenience of a smartphone, tablet or laptop.

Convenience is a massive issue when it comes to developing a gaming website. A quick look at the Kongregate website reveals not only a wide range of games, but the load time has been slashed due to the efficient use of graphics and limited screen size that has been key to ensuring that this is a go-to for many fledgling games developers.

Whereas Armor Games have aimed to make their gaming site a little more personal thanks to the full integration with social networks and login options to enable a deeper and more user-friendly gaming experience.

So whether you’re building a gaming website that helps users find the latest casino jackpot, or delivering a more immersive audiovisual experience, there’s plenty to consider on your ambitious gaming site.

 

5 Easiest WebGL Tools To Use

So you want to run fancy interactive 3D media on your website without any fancy shmancy plug-ins. Well, that‘s just fine, because you‘re living in the future, and the future supports WebGL. It‘s also supported by any browser you care to name – if it can‘t run WebGL, it‘s either outdated or used by 6 people around the world. But what tools should you use if you‘re just starting out and don‘t really know much of programing?

Unreal Engine 4

Unreal Engine is the big kid on the block. It‘s used to power some of the biggest games on the block – on the future block, too, seing how the top-of-the-line Samsung Gear VR game EVE Gunjack runs on it. It‘s freshly introducing blueprints which allows developers to drag-n-drop variables and actions instead of programming everything by hand. Of course, scripting is still available for pros, but newbie-friendlyness is one of the main selling points!

Unity 5

Unity is the other white meat… er, easy to use developer tool with WebGL support. Unity runs roughly all of the indie games out there, from Kickstarter darlings like Wasteland 2 to anything available on Samsung Gear VR that‘s not EVE Gunjack. Much like Unreal Engine 4, it also supports game design without actual coding, though it‘s flexible enough to allow for people with scripting experience. Make use of the bajillion tutorials available for it, too.

Goo Create

Goo Create doesn‘t even want you to leave the browser. It allows you to create WebGL games, apps and animations without coding and for free. Hell, you can create immersive ads that people won‘t mind seeing and exploring, if you‘re good enough. Just drag and drop stuff until you are done! Their website itself demonstrates the kind of interactive fun that WebGL is capable of, and there are a few demonstrations covering the main areas of use.

Clara.io

You‘re not going anywhere without models, buster. Clara.io is the a 3D modeling platform in WebGL and it allows you to make your own 3D models online, for free. Just sign it and start creating, and soon you‘ll have tanks, space ships and other fancy objects aplenty. Of course, you might desire models that are a little more refined than the ones you just made, so you can always turn your gaze to websites like CGTrader. They have thousands of low-poly models (you know, just the kind of model you want for games and apps) in their libraries. And as is the case with aforementioned CGTrader, there are many free 3D models too, which allow you to skip the whole „3D modeling“ phase.

Chrome Experiments

This website will serve as an inspiration in your many trials and travails with WebGL. These users have already made some strange and wondrous stuff – lighsaber simulators included – so give them a spin. Who knows, they might inspire you to do something fresh (or fresh-ish) and show you the heights that WebGL can take you to. One day you might also be one of them!
So there you have it. These are all good tools for an aspiring WebGL developer. From software with premade blocks of states and actions to be used instead of coding to 3D modeling suites run on WebGl, to Chrome Experiment, everything is at your fingertips.

 

How to Take Back Control of Your Website

As your company grows, you take on IT experts that immediately start telling you what to do. The loss of control may have even started before that. It is possible that you were convinced that producing a website would be too hard, and that you were unqualified to deal with it. If you turned the creation of your site over to a consultant during its embryonic phase, then you never really had control of your site in the first place.

No worries. It’s still not too late to take back control of your site. Here’s how:

Trust Your User Instincts

You don’t have to be a professional web designer to have a worthwhile opinion about your own website. Often, web designers are in a bubble that keeps them from understanding how regular people use the web. User experience is everything. You may not be an expert designer, but you are an expert user. Your user experience can inform about aspects such as:

  • Home page attractiveness
  • Choice of images
  • Impression of clutter
  • Navigation simplicity

Your judgement about these things is valid. Take control by using your valid judgements as a user, to guide the decisions shaping your website.

Make the Decisions that Matter

It’s your site. You can and should take control of making all the important decisions regarding how that site runs. After all, the responsibility is yours whether or not you outsourced the decision making. There is plenty about your site that requires executive control.

  • What kind of ads are you going to run? To the user, there is no distinction between an ad on your site, and the sites content that you create. You need to decide everything from how salacious you want the ads to be, to how many and how aggressive they are.
  • What is your mobile strategy? Is your desktop site mobile responsive, or will you have a separate mobile site? Will you provide an app for an even better mobile experience?
  • What platforms will you cater to? Are you targeting iOS only, or iOS and Android? Which Androids? That can be a real problem for developers. What are your plans for Windows Phone and Blackberry?
  • When it comes to ecommerce, do you want to be able to take Apple Pay, or just accept whatever the web host provides?
  • This list goes on…

Know What You Don’t Know

A little humility goes a long way. Of course it is your site. Everyone knows that. And there is plenty that you can and should control. But you are not a technician or security expert. There are things that you don’t know. And you need to be well aware of what those things are. You don’t want to be one of those people who doesn’t know what you don’t know, and makes of mess of everything in your zeal to make things better.
Once you know what you don’t know, outsource that part to a trusted company. Even then, you never take your hand completely off the wheel. The support staff answers to you, even if that support staff is a third-party. For example, you make look to an IT support company like Firewall Technical for managed services, but still retain full website control. Speaking in general, they describe one of the benefits of such a service this way:
It does not take long for a business to fall behind on IT maintenance. If a business fails to keep up with things such as patches, backups, upgrades or security it can quickly result in numerous issues. IT outages, or other costly IT issues can seriously harm a business. To give an example, a faulty email server or network failure can result in a loss in income and a loss in productivity.
By outsourcing daily IT duties, a business will free up its internal resources and reduce the number of IT-related business interruptions.
When you know what you don’t know, then you can free up resources to do what you do best.
You wouldn’t let your marketing run amuck without supervision. So why would you do that for your website? Now is the time to take back control of one of the most important aspects of your business.

 
2017 All rights reserved | Powered by WordPress
Back to top
Theme by dynamicguru.com