Every time you write the code, open the FileZilla, write the file uploaded to the VPS, over the longer feel bored, wondering if there is more geek method, there is this article.
Webhook is the technology that comes with git, when you push to the server, the server sends a special request to the URL you specify, and we can use the scripting language to get the request and execute the GIT pull on the VPS to achieve the purpose of automatic deployment, the usual first code :
<?php/** * Simple Git WebHook SDK * * @coding. NET * 2016/05/09 * author:hldh214 <[email protected]> * *//configuration item Start$git _dir='/var/www/.git ';$work _tree='/var/www ';//Configuration item End//Get the original request$hook _log= File_get_contents (' Php://input ');//Use MySQL log log$fh= Mysqli_connect (' localhost ',' Root ',' Root ',' git ');//Determine if the request is Webhookif(!Empty($hook _log)) {//Is Webhook request, and decode data $json= Json_decode ($hook _log,true);if(Array_key_exists (' ref ',$json)) {//Ref key detected, execute pull $cmd="/usr/bin/sudo git--git-dir= $git _dir--work-tree= $work _tree pull 2>&1";$sh _log= Shell_exec ($cmd);$sql="INSERT into ' webhook_log ' (' Hook_log ', ' sh_log ', ' Date ') VALUES ('".$hook _log."', '".$sh _log."', Current_date ());";//Log execution Log $result= Mysqli_query ($fh,$sql); }Else{//No ref key detected, for test request $sh _log=' testing ';$sql="INSERT into ' webhook_log ' (' Hook_log ', ' sh_log ', ' Date ') VALUES ('".$hook _log."', '".$sh _log."', Current_date ());";$result= Mysqli_query ($fh,$sql); }}Else{//Normal access Echo ' ;}
Upload this code to the VPS with FileZilla (the last time you use FileZilla <3), fill in the URL of the php file into the deploy_url of the Webhook page, and click Test, Then go back to the VPS to see if MySQL already has log, and then try Commit&push in the development machine, you will find that the code has been quietly deployed to the VPS.
Webhook's PHP practice @coding.net