Skip to content

Instantly share code, notes, and snippets.

@rudiedirkx
Last active May 3, 2026 12:15
Show Gist options
  • Select an option

  • Save rudiedirkx/5e4767113ce3456d720afe6c653c40f6 to your computer and use it in GitHub Desktop.

Select an option

Save rudiedirkx/5e4767113ce3456d720afe6c653c40f6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
$args = array_slice($_SERVER['argv'], 1);
$backup = !in_array('--no-backup', $args);
if (!file_exists('.env')) {
echo "Must be in root dir.\n";
exit(1);
}
echo "Backup: " . ($backup ? "YES" : "NO") . "\n\n";
echo "GIT STATUS...\n====\n";
echo shell_exec("git status");
echo "====\nPress ENTER to continue, or CTRL-X out. ";
readline();
echo "\n\n";
echo "GIT OUT...\n====\n";
echo shell_exec("git fetch");
echo shell_exec("git plog HEAD..FETCH_HEAD --no-merges");
echo "\n====\nPress ENTER to continue, or CTRL-X out. ";
readline();
echo "\n\n";
echo "Extracting db credentials...\n";
$cfg = file_get_contents('.env');
if (!preg_match('#DB_DATABASE=(\S+)#', $cfg, $match)) {
echo "Can't extract db name.\n";
exit(1);
}
$db = $match[1];
if (!preg_match('#DB_USERNAME=(\S+)#', $cfg, $match)) {
echo "Can't extract db user.\n";
exit(1);
}
$user = $match[1];
if (!preg_match('#DB_PASSWORD=(\S+)#', $cfg, $match)) {
echo "Can't extract db pass.\n";
exit(1);
}
$pass = $match[1];
echo "Done.\n\n";
echo "Powering DOWN...\n";
echo shell_exec("sudo supervisorctl stop laravel-worker");
echo shell_exec("./artisan down");
echo "Done.\n\n";
echo "Clearing caches...\n";
echo shell_exec("./artisan cache:clear");
echo shell_exec("./artisan config:clear");
echo shell_exec("./artisan view:clear");
echo shell_exec("./artisan twig:clean");
echo "Done.\n\n";
if ($backup) {
echo "Dumping db...\n";
echo shell_exec("mysqldump -u{$user} -p{$pass} {$db} > ~/backups/pre-deploy.sql");
echo "Done.\n\n";
}
echo "Pulling in GIT...\n";
echo shell_exec("git pull");
echo "Done.\n\n";
echo "Running composer...\n";
echo shell_exec("composer install -a --no-dev --prefer-dist --no-interaction --no-progress");
echo "Done.\n\n";
echo "chmod writables...\n";
echo shell_exec("chmod -R 0777 storage bootstrap/cache public/images/uploads");
echo "Done.\n\n";
echo "Re-cache routes...\n";
echo shell_exec("./artisan route:clear");
echo shell_exec("./artisan route:scan");
echo shell_exec("./artisan model:scan");
echo shell_exec("./artisan route:cache");
echo "Done.\n\n";
echo "Migration status...\n====\n";
echo shell_exec("./artisan migrate:status");
//echo shell_exec("./artisan migrate --pretend");
echo "====\nPress ENTER to continue, or CTRL-X out. ";
readline();
echo "\n\n";
echo "Run migrations...\n";
$output = shell_exec("./artisan migrate -vvv --step");
echo $output;
if (strpos($output, 'Exception trace') !== false) {
echo "\nERROR. QUITTING.\n\n";
exit(1);
}
echo "Done.\n\n";
echo "Import new translations...\n";
echo shell_exec("./artisan translation:sync");
echo "Done.\n\n";
echo "Caching abilities...\n";
echo shell_exec("./artisan auth:policies");
echo "Done.\n\n";
echo "Styling portals...\n";
echo shell_exec("./artisan icares:style-portals");
echo "Done.\n\n";
echo "Chmodding writables...\n";
echo shell_exec("chmod -R 0777 storage bootstrap/cache public/images/uploads");
echo "Done.\n\n";
echo "Power UP...\n";
echo shell_exec("./artisan buildstamp");
echo shell_exec("./artisan config:cache");
echo shell_exec("./artisan up");
echo shell_exec("sudo supervisorctl start laravel-worker");
echo "Done.\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment