4.9 KiB
Laravel Hostinger Deploy
A Laravel package for automated deployment to Hostinger shared hosting with GitHub Actions support.
Features
- 🚀 One-command deployment to Hostinger shared hosting
- 🔄 GitHub Actions integration for automated deployments
- 🔑 Automatic SSH key management for secure connections
- 📦 Laravel-specific optimizations (composer, migrations, storage links)
- ⚙️ Configurable deployment options via config file
Installation
Install the package via Composer:
composer require zura/laravel-hostinger-deploy --dev
Configuration
1. Environment Variables
Add the following variables to your .env file:
# Hostinger Deployment Configuration
HOSTINGER_SSH_HOST=your-server-ip
HOSTINGER_SSH_USERNAME=your-username
HOSTINGER_SSH_PORT=22
HOSTINGER_SITE_DIR=your-website-folder
2. Publish Configuration (Optional)
Publish the configuration file to customize deployment options:
php artisan vendor:publish --tag=hostinger-deploy-config
This will create config/hostinger-deploy.php with customizable options.
Usage
1. Deploy to Hostinger
Deploy your Laravel application to Hostinger shared hosting:
php artisan hostinger:deploy-shared
Options:
--fresh: Delete existing files and clone fresh repository--site-dir=: Override site directory from config
2. Publish GitHub Actions Workflow
Create a GitHub Actions workflow file for automated deployments:
php artisan hostinger:publish-workflow
Options:
--branch=: Override default branch (default: auto-detect)--php-version=: Override PHP version (default: 8.3)
3. Setup Automated Deployment
Configure SSH keys and display GitHub secrets for automated deployment:
php artisan hostinger:auto-deploy
This command will:
- Generate SSH keys on your Hostinger server
- Display all required GitHub secrets and variables
- Provide step-by-step instructions for GitHub setup
GitHub Actions Setup
After running php artisan hostinger:auto-deploy, you'll need to add the following to your GitHub repository:
Secrets (Repository Settings → Secrets and variables → Actions → Secrets)
SSH_HOST: Your Hostinger server IP addressSSH_USERNAME: Your Hostinger SSH usernameSSH_PORT: Your Hostinger SSH port (usually 22)SSH_KEY: Your private SSH key (displayed by the command)
Variables (Repository Settings → Secrets and variables → Actions → Variables)
WEBSITE_FOLDER: Your Hostinger website folder name
Deploy Keys (Repository Settings → Deploy keys)
Add the public SSH key displayed by the auto-deploy command as a deploy key.
Workflow
The generated GitHub Actions workflow will:
- Checkout code from your repository
- Setup PHP environment
- Install dependencies via Composer
- Generate application key and create storage link
- Run database migrations
- Deploy to Hostinger via SSH
- Update code on the server and run optimizations
Configuration Options
SSH Settings
'ssh' => [
'host' => env('HOSTINGER_SSH_HOST'),
'username' => env('HOSTINGER_SSH_USERNAME'),
'port' => env('HOSTINGER_SSH_PORT', 22),
'timeout' => 30,
],
Deployment Settings
'deployment' => [
'site_dir' => env('HOSTINGER_SITE_DIR'),
'composer_flags' => '--no-dev --optimize-autoloader',
'run_migrations' => true,
'run_storage_link' => true,
'run_config_cache' => false,
'run_route_cache' => false,
'run_view_cache' => false,
],
GitHub Actions Settings
'github' => [
'workflow_file' => '.github/workflows/hostinger-deploy.yml',
'php_version' => '8.3',
'default_branch' => 'main',
],
Requirements
- PHP ^8.2
- Laravel ^11.0|^12.0
- SSH access to Hostinger server
- Git repository with GitHub integration
Troubleshooting
SSH Connection Issues
- Verify your SSH credentials in
.env - Test SSH connection manually:
ssh -p PORT USERNAME@HOST - Ensure SSH key authentication is working
GitHub Actions Issues
- Verify all secrets and variables are correctly set
- Check that the deploy key is added to your repository
- Ensure the workflow file is committed and pushed
Deployment Issues
- Check that your Hostinger server has Composer installed
- Verify the site directory exists and is writable
- Ensure your Laravel application is properly configured
Security Notes
- SSH keys are generated on the server and should be kept secure
- Private keys are displayed for GitHub setup - copy them carefully
- The package uses SSH key authentication for secure deployments
License
This package is open-sourced software licensed under the MIT license.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you encounter any issues or have questions, please open an issue on GitHub.