Last active
February 3, 2018 15:49
-
-
Save Billcountry/1365d970f87a1b9ac04775b5fcbbdeb1 to your computer and use it in GitHub Desktop.
This file will deploy your git repository to a php server or the directory it's. It's convenient for cpanel hosting and you can add it's URL as a web-hook so that it's updated every time you push your updates to git.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('display_errors', 1); | |
header('Content-Type: text/plain'); | |
$account = '_YOUR_ACCOUNT_NAME_'; // Example Billcountry | |
$repo = '_REPO_TO_DEPLOY_'; // iF i NEED TO EXPLAIN THIS YOU SHOULD PROBABLY LEAVE | |
$branch = '_BRANCH_TO_DEPLOY_'; | |
$url = "https://github.com/$account/$repo/archive/$branch.zip"; | |
echo("Cloning into $url\n"); | |
$path = dirname(__FILE__)."/$branch.zip"; | |
$data = fopen($url, 'r'); | |
echo("Writing Zip File\n"); | |
file_put_contents($path, $data); | |
echo("Extracting ZIP\n"); | |
$zip = new ZipArchive; | |
if ($zip->open($path) === TRUE) { | |
$zip->extractTo(dirname(__FILE__)); | |
echo "All files extracted to: $repo-$branch\n"; | |
$zip->close(); | |
$source = dirname(__FILE__)."/$repo-$branch"; | |
$destination = dirname(__FILE__); | |
echo "Removing old files:\n"; | |
$old_files = scandir($source); | |
foreach($old_files as $file){ | |
if($file !== '.' && $file !== '..' && $file !== "$repo-$branch" && $file !== "deploy.php"){ | |
echo "\t$file\n"; | |
exec("rm -R $destination/$file"); | |
} | |
} | |
echo("No more old files\n"); | |
echo "Moving files:\nSource: $source \nDestination: $destination\n"; | |
exec("mv -f $source/* $source/.* $destination/"); | |
echo "Removing source folder\n"; | |
exec("rm $source -R"); | |
echo "Removing source zip\n"; | |
exec("rm $path"); | |
echo "Done"; | |
} else { | |
echo 'Failed to extract Zip, please retry.\n'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment