Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting automatic GIT deployment of PHP project
    primarykey
    data
    text
    <p>What I want to do is, to switch from FTP deployment into GIT. I mean, I want to keep automatically keep synced my Bitbucket private repo and my shared webhosting. I googled and found following script to deploy my webserver (<a href="http://www.stephenradford.me/blog/tutorials/deploy-via-bitbucket-or-github-service-hooks">based on this article</a>). </p> <pre><code>// Set these dependant on your BB credentials $username = 'username'; $password = 'password'; // Grab the data from BB's POST service and decode $json = stripslashes($_POST['payload']); $data = json_decode($json); // Set some parameters to fetch the correct files $uri = $data-&gt;repository-&gt;absolute_url; $node = $data-&gt;commits[0]-&gt;node; $files = $data-&gt;commits[0]-&gt;files; // Foreach through the files and curl them over foreach ($files as $file) { if ($file-&gt;type == "removed") { unlink($file-&gt;file); } else { $url = "https://api.bitbucket.org/1.0/repositories" . $uri . "raw/" .$node ."/" . $file-&gt;file; $path = $file-&gt;file; $dirname = dirname($path); if (!is_dir($dirname)) { mkdir($dirname, 0775, true); } $fp = fopen($path, 'w'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_FILE, $fp); $data = curl_exec($ch); curl_close($ch); fclose($fp); } } </code></pre> <p>The problem is, this works on simple changesets like 5-10 file change. But when I push the whole project for the first time (for example with 600-700 files and folders) into my bitbucket private profile, this script doesn't work. (just doesn't, no error on errors.log)</p> <p>What am I missing? </p> <p>By the way, Can I do something like that: </p> <p>As we know, Bitbucket can send POST information into an exact url (given by user) directly after a commit has been made. So when deploy.php receives POST, we can get the entire commit as a zip or tar, clean our current files and unzip the new commit into webserver. </p> <p>Is that possible? If yes then how? Any other good way? </p> <h1>Update</h1> <p>I found the code below for automated deploying php project. The problem is <code>https://bitbucket.org/$username/$reponame/get/tip.zip</code> this url doesnt work on bitbucket private git repo: probably related with authentication (I haven't tested this on public repo) What i need is to get the last commit's zip file and unzip inside my project. </p> <pre><code>&lt;? // your Bitbucket username $username = "edifreak"; // your Bitbucket repo name $reponame = "canvas-game-demo"; // extract to $dest = "./"; // leave ./ for relative destination //////////////////////////////////////////////////////// // Let's get stuff done! // set higher script timeout (for large repo's or slow servers) set_time_limit(380); // download the repo zip file $repofile = file_get_contents("https://bitbucket.org/$username/$reponame/get/tip.zip"); file_put_contents('tip.zip', $repofile); unset($repofile); // unzip $zip = new ZipArchive; $res = $zip-&gt;open('tip.zip'); if ($res === TRUE) { $zip-&gt;extractTo('./'); $zip-&gt;close(); } else { die('ZIP not supported on this server!'); } // delete unnecessary .hg files @unlink("$username-$reponame-tip/.hgignore"); @unlink("$username-$reponame-tip/.hg_archival.txt"); // function to delete all files in a directory recursively function rmdir_recursively($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." &amp;&amp; $object != "..") { if (filetype($dir."/".$object) == "dir") rmdir_recursively($dir."/".$object); else unlink($dir."/".$object); } } reset($objects); rmdir($dir); } } // function to recursively copy the files function copy_recursively($src, $dest) { if (is_dir($src)) { if($dest != "./") rmdir_recursively($dest); @mkdir($dest); $files = scandir($src); foreach ($files as $file) if ($file != "." &amp;&amp; $file != "..") copy_recursively("$src/$file", "$dest/$file"); } else if (file_exists($src)) copy($src, $dest); rmdir_recursively($src); } // start copying the files from extracted repo and delete the old directory recursively copy_recursively("$username-$reponame-tip", $dest); // delete the repo zip file unlink("tip.zip"); // Yep, we're done :) echo "We're done!"; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload