-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-api.php
More file actions
32 lines (28 loc) · 1.06 KB
/
deploy-api.php
File metadata and controls
32 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
/**
* cPanel Git Deployment Trigger
* This script is called by GitHub Webhooks to trigger a 'git deploy' on cPanel.
*
* Instructions:
* 1. Place this file in your public_html folder.
* 2. In GitHub Repository Settings > Webhooks, add this URL:
* https://yourdomain.com/deploy-api.php
*/
// Optional: Add a simple security token check
// if ($_GET['token'] !== 'your_secret_token') {
// die('Unauthorized');
// }
// 1. Trigger the cPanel git-deploy
$output = [];
$return_var = 0;
exec('/usr/local/cpanel/3rdparty/bin/git-deploy 2>&1', $output, $return_var);
// 2. Log the deployment for debugging
$log = "[" . date('Y-m-d H:i:s') . "] Deployment triggered. Status: $return_var\nOutput: " . implode("\n", $output) . "\n---\n";
file_put_contents(__DIR__ . '/deploy_log.txt', $log, FILE_APPEND);
if ($return_var === 0) {
echo json_encode(['success' => true, 'message' => 'Deployment successful!', 'output' => $output]);
} else {
http_response_code(500);
echo json_encode(['success' => false, 'message' => 'Deployment failed.', 'output' => $output]);
}
?>