cPanel Git Version Control позволяет клонировать GitHub/GitLab репозиторий прямо на хостинг и автоматически деплоить изменения при push.
Настройка Git Version Control
cPanel → Files → Git Version Control → Create.
Clone URL: https://github.com/username/mysite.git
Repository Path: /home/user/public_html
Repository Name: mysite
✅ Для приватных репозиториев добавьте SSH-ключ хостинга в GitHub: cPanel → Security → SSH Access → Manage SSH Keys → скопируйте публичный ключ в GitHub → Settings → SSH keys.
Автодеплой через .cpanel.yml
Создайте файл .cpanel.yml в корне репозитория:
---
deployment:
tasks:
- export DEPLOYPATH=/home/user/public_html
- /bin/cp -r $SRCDIR/* $DEPLOYPATH
- cd $DEPLOYPATH && composer install --no-dev
- cd $DEPLOYPATH && php artisan migrate --force
Ручной деплой через SSH
# Перейти в папку репозитория
cd ~/repositories/mysite
# Получить изменения
git pull origin main
# Обновить production файлы
rsync -av --delete ./ ~/public_html/ --exclude='.git'
Webhook для автодеплоя из GitHub
<?php
// deploy.php
$secret = 'your_webhook_secret';
$payload = file_get_contents('php://input');
$sig = 'sha256=' . hash_hmac('sha256', $payload, $secret);
if (!hash_equals($_SERVER['HTTP_X_HUB_SIGNATURE_256'], $sig)) {
http_response_code(403);
exit;
}
exec('cd /home/user/public_html && git pull origin main 2>&1', $output);
echo implode("
", $output);
⚠️ Никогда не размещайте папку .git в public_html без защиты! Добавьте в .htaccess:
RedirectMatch 404 /\.git