thetamari/laravel-hostinger
最新稳定版本:v1.0.6
Composer 安装命令:
composer require thetamari/laravel-hostinger
包简介
A Laravel package to deploy private GitHub repositories to Hostinger shared hosting via SSH, with automated webhook-based auto-deployment on push.
README 文档
README
A Laravel Composer package for deploying private GitHub repositories to Hostinger shared hosting via SSH, with full auto-deploy on push via GitHub webhooks.
Hostinger shared hosting does not support server-side git hooks, does not let you change the web root away from public_html, and its built-in GitHub auto-deploy only copies into public_html — making it unsuitable for Laravel. This package solves all of that.
Table of Contents
How it works
~/domains/yourdomain.com/ ← Laravel lives here (cloned from GitHub)
~/domains/yourdomain.com/public_html → symlink → ~/domains/yourdomain.com/public
When you push to GitHub, a webhook fires your Hostinger-hosted receiver, which triggers php artisan hostinger:deploy --pull-only in the background — pulling code, running composer, npm run build, migrating, and caching automatically.
Requirements
- PHP 8.1+
- Laravel 10, 11, or 12
- SSH access enabled on your Hostinger plan (Business or above)
- An SSH key pair added to Hostinger hPanel → SSH Keys
- Composer installed on Hostinger (available via hPanel)
- Node.js available via
/opt/alt/alt-nodejs24(or adjust the path in config)
Installation
- Install the package, then run the prepare command to patch your project files:
composer require thetamari/laravel-hostinger php artisan hostinger:prepare
Optionally publish the config file if you want to customize it directly:
php artisan vendor:publish --tag=hostinger-deploy-config
- Fill in your local
.envwith allHOSTINGER_*values from the Configuration section below. - ⚠⚠ Important: Commit and push your project to GitHub before the next step.
- Run the deploy command locally on your computer — this SSHs into Hostinger, clones your repo, installs dependencies, and sets everything up:
php artisan hostinger:deploy
- Once the first deploy is done, run the webhook setup command to get the details needed for GitHub:
php artisan hostinger:setup-webhook
From this point on, every push to your branch triggers an automatic re-deploy via the GitHub webhook.
Configuration
Add the following values to your .env and .env.example files. The SSH values are only required locally on your computer for initial deployment, but the rest are needed for the remainder of the functionality:
# SSH connection to Hostinger # Port is typically 65002 on Hostinger shared hosting HOSTINGER_SSH_HOST= HOSTINGER_SSH_PORT=65002 HOSTINGER_SSH_USER= HOSTINGER_SSH_KEY_PATH=~/.ssh/id_rsa HOSTINGER_SSH_KEY_PASSPHRASE= # The folder name inside ~/domains/ on Hostinger # e.g. if your site lives at ~/domains/yourdomain.com → HOSTINGER_WEBSITE_FOLDER=yourdomain.com HOSTINGER_WEBSITE_FOLDER= HOSTINGER_WEBSITE_URL=https://yourdomain.com # PHP, Node, and Composer binary paths on Hostinger # Adjust version numbers to match what you've selected in hPanel HOSTINGER_PHP_BIN=/opt/alt/php85/usr/bin/php HOSTINGER_COMPOSER_BIN=/usr/local/bin/composer HOSTINGER_NODE_BIN=/opt/alt/alt-nodejs24/root/usr/bin/node HOSTINGER_NPM_BIN=/opt/alt/alt-nodejs24/root/usr/bin/npm # Adjust node memory limit for shared hosting HOSTINGER_NODE_MEMORY_LIMIT=512 # GitHub fine-grained PAT (Personal Access Token) # Required permissions: # - Contents: Read-only # - Metadata: Read-only (granted automatically) # If using a classic PAT, enable the `repo` scope. HOSTINGER_GITHUB_PAT= HOSTINGER_GITHUB_REPO=username/repo-name HOSTINGER_GITHUB_BRANCH=main # Webhook # Secret must match what you enter in GitHub's webhook settings # Generate one with: openssl rand -hex 32 HOSTINGER_WEBHOOK_SECRET= HOSTINGER_WEBHOOK_ROUTE=deploy/webhook # Remote log file path on Hostinger # Use the full path inside your Laravel project for best results # Leave empty to disable remote logging HOSTINGER_LOG_PATH=~/domains/yourdomain.com/storage/logs/deploy.log
GitHub PAT Permissions
Create a fine-grained PAT at github.com/settings/tokens with:
| Permission | Access |
|---|---|
| Contents | Read-only |
| Metadata | Read-only (auto-granted) |
If using a classic PAT, enable the repo scope.
Commands
Prepare your project
Run once before your first push to patch your project files:
php artisan hostinger:prepare
This adds the webhook route to your CSRF exclusions in bootstrap/app.php and adds .rnd to your .gitignore. On Laravel 10 the CSRF patch is not automatic — see the Auto-deploy setup section.
First-time deploy
Clones the repo, runs composer install, sets up .env, generates an app key, runs migrations, builds assets, and creates the public_html and storage symlinks.
php artisan hostinger:deploy
The command will pause after copying .env.example to .env so you can SSH in (or use Hostinger's file manager for your website) and fill in production values before continuing. It's important to fill in the HOSTINGER_* values too (except SSH values).
It will also pause if migration fails because of database connection issues and give you the opportunity to fix them then continue without starting over.
Options:
| Option | Description |
|---|---|
--skip-npm |
Skip npm install and npm run build |
--skip-migrate |
Skip database migrations |
--run-npm |
Force npm build |
--pull-only |
Pull latest code and run post-deploy steps only (no wipe/clone) |
--ssh |
Run pull-only via SSH from your local machine instead of directly on the server |
Re-deploy (code update only)
php artisan hostinger:deploy --pull-only --run-npm
Pulls the latest code, runs composer install, migrations, and rebuilds the cache. Also runs npm install and npm run build. Does not wipe the directory or touch .env.
To manually trigger a re-deploy from your local machine via SSH:
php artisan hostinger:deploy --pull-only --ssh --run-npm
Set up auto-deploy webhook
php artisan hostinger:setup-webhook
This prints your webhook URL, generates a secret if you don't have one, and gives you the exact GitHub settings to use.
Auto-deploy setup (after first deploy)
The webhook is a standard Laravel POST route registered by the package — no standalone PHP files, no public directory hacks.
Running hostinger:prepare automatically adds the webhook route to your CSRF exclusions in bootstrap/app.php. On Laravel 10 this is not patched automatically — add it manually to app/Http/Middleware/VerifyCsrfToken.php:
protected $except = [ 'deploy/webhook', ];
1. Run php artisan hostinger:setup-webhook — this will give you your webhook URL and secret.
2. Create the webhook — Use the printed details to add a webhook in your GitHub repo → Settings → Webhooks → Add webhook:
- Payload URL:
https://yourdomain.com/deploy/webhook - Content type:
application/json - Secret: your
HOSTINGER_WEBHOOK_SECRET - Events: Just the push event
3. Push to your branch. GitHub sends a signed payload to your Laravel app, which verifies the HMAC-SHA256 signature and runs hostinger:deploy --pull-only in the background. The webhook always runs npm run build.
Security note: The URL itself does not need to be obscure. Every request is verified against a cryptographic signature using your HOSTINGER_WEBHOOK_SECRET. Requests without a valid signature are rejected with a 403 before any deploy logic runs.
Logging
All deploy activity is logged to the remote path defined in HOSTINGER_LOG_PATH (default: ~/domains/yourdomain.com/storage/logs/deploy.log). You can tail it:
ssh -p 65002 user@yourhost "tail -f ~/domains/yourdomain.com/storage/logs/deploy.log"
Set HOSTINGER_LOG_PATH= (empty) to disable remote logging.
A lock file (storage/logs/hostinger-deploy.lock) is created at the start of each webhook-triggered deploy and removed when it completes. If two pushes arrive simultaneously, the second is skipped since the first deploy will already include the latest code. Stale lock files older than 10 minutes are automatically removed.
PHP & Node version
Hostinger uses alt-php and alt-nodejs from CloudLinux. Default paths in this package:
PHP: /opt/alt/php85/usr/bin/php
Node: /opt/alt/alt-nodejs24/root/usr/bin/node
npm: /opt/alt/alt-nodejs24/root/usr/bin/npm
If your hPanel is configured to use a different version, update HOSTINGER_PHP_BIN, HOSTINGER_NODE_BIN, and HOSTINGER_NPM_BIN accordingly.
Also, make sure to set the HOSTINGER_NODE_MEMORY_LIMIT value as unlimited memory values can crash your npm run build command especially on low memory shared hosting environments.
Security
- Your GitHub PAT is used only over HTTPS and never stored on the remote server beyond the git remote URL (which is reset on each pull). Consider rotating it periodically.
- The webhook endpoint validates the
X-Hub-Signature-256header using HMAC-SHA256. Requests with an invalid or missing signature are rejected with a 403. - Never commit your
.envor expose your PAT or webhook secret.
License
MIT — see LICENSE.
Author
TheTamari · github.com/thetamari
Credits
Inspired by TheCodeHolic · github.com/thecodeholic
thetamari/laravel-hostinger 适用场景与选型建议
thetamari/laravel-hostinger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「deploy」 「github」 「ssh」 「laravel」 「deployment」 「devops」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 thetamari/laravel-hostinger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thetamari/laravel-hostinger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 thetamari/laravel-hostinger 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Handles basic OAuth/OAuth2 authentication along with classes for common services
blueways deployer recipes
The Laragoon utility package
A Highly Opinionated Symfony3/4 Deployer Recipe
MediaWiki extension that allows embedding external content, specified by URL, into your wiki pages
A flexible FTP, SSL-FTP, and SSH-based SFTP client for PHP. This lib provides helpers that are easy to use to manage the remote files.
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 34
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-22