Cara Membuat Auto Deploy GitHub ke CyberPanel Menggunakan Webhook (Gratis Tanpa GitHub Actions)

Saat mengembangkan website yang disimpan di GitHub, proses deploy biasanya dilakukan secara manual menggunakan SSH:

git pull

Pada artikel ini kita akan membuat sistem Auto Deploy gratis menggunakan GitHub Webhook, CyberPanel, OpenLiteSpeed, dan PHP.

Arsitektur

Developer
    │
    ▼
GitHub Repository
    │
    ▼
GitHub Webhook
    │
    ▼
https://domain.com/deploy
    │
    ▼
deploy.php
    │
    ▼
git pull origin main
    │
    ▼
Website otomatis ter-update

Prasyarat

  • CyberPanel sudah terinstall
  • Repository sudah berada di server
  • Git sudah terinstall
  • Deploy Key GitHub sudah berfungsi
  • HTTPS aktif

Langkah 1 - Clone Repository

cd /home/pathwebsite

git clone git@github.com:username/repo.git public_html

Langkah 2 - Membuat deploy.php

<?php

$secret = 'YOUR-SECRET-KEY';

$signature = $_SERVER['HTTP_X_HUB_SIGNATURE_256'] ?? '';

if (empty($signature)) {
    http_response_code(403);
    exit('Missing signature');
}

$payload = file_get_contents('php://input');

$expected = 'sha256=' . hash_hmac(
    'sha256',
    $payload,
    $secret
);

if (!hash_equals($expected, $signature)) {
    http_response_code(403);
    exit('Invalid signature');
}

$data = json_decode($payload, true);

if (($data['repository']['name'] ?? '') !== 'repo-name') {
    exit('Ignored repository');
}

if (($data['ref'] ?? '') !== 'refs/heads/main') {
    exit('Ignored branch');
}

exec(
    'cd /home/path/to/website/public_html && git pull origin main 2>&1',
    $output,
    $return
);

file_put_contents(
    __DIR__ . '/deploy.log',
    "\n[" . date('Y-m-d H:i:s') . "]\n" .
    implode("\n", $output) .
    "\nRETURN=" . $return . "\n",
    FILE_APPEND
);

echo 'Deployment successful';

Langkah 3 - Tambahkan Route Deploy

RewriteRule ^deploy/?$ deploy.php [L,QSA]

Langkah 4 - Membuat Webhook GitHub

  • Payload URL: https://domain.com/deploy
  • Content Type: application/json
  • Secret: YOUR-SECRET-KEY
  • SSL Verification: Enable SSL Verification
  • Event: Just the push event
  • Active: Centang Active

Langkah 5 - Test Deploy

git add .
git commit -m "test auto deploy"
git push origin main

Melihat Log Deploy

cat /home/username/public_html/deploy.log

Troubleshooting

Error 403

Pastikan secret pada GitHub Webhook dan deploy.php sama persis.

Permission Denied (publickey)

git pull

Jika gagal, periksa Deploy Key GitHub.

Webhook 200 Tapi Tidak Deploy

Pastikan path repository yang digunakan benar:

/home/username/public_html

Keuntungan

  • Gratis
  • Tidak membutuhkan GitHub Actions
  • Mendukung repository private
  • Cocok untuk CyberPanel dan OpenLiteSpeed
  • Deploy otomatis setiap push ke branch main

Kesimpulan

Setelah konfigurasi selesai, cukup lakukan:

git push origin main

Maka server akan otomatis menjalankan deploy tanpa perlu login SSH dan menjalankan git pull secara manual.

Posting Komentar

0 Komentar