amirvahedix / laravel-deploy-ftp
A Laravel package to deploy files modified in Git to an FTP server based on commits, tags, or git status.
Requires
- php: ^8.2
- illuminate/console: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
README
A lightweight Laravel package to deploy files modified in Git (plus compiled assets like public/build) to any shared hosting or server via FTP/FTPS.
Features
- ๐ Git-based deployment: Deploy modified files based on Git commits, tags, or
git status. - ๐ Asset inclusion: Automatically includes compiled frontend assets (
public/build). - ๐ Exclusions: Automatically excludes sensitive
.envfiles,.git/,vendor/,node_modules/, and custom specified paths. - โ๏ธ Config &
.envdriven: Easily configured viaconfig/deploy-ftp.phpor.envvariables. - ๐งช Dry-run mode: Preview files to be uploaded before performing actual transfer.
Installation
Install the package via Composer in any Laravel project:
composer require amirvahedix/laravel-deploy-ftp
(The package uses Laravel Service Discovery and will automatically register the deploy:ftp Artisan command).
Configuration
Publish the package configuration file to config/deploy-ftp.php:
php artisan vendor:publish --tag=deploy-ftp-config
Environment Variables (.env)
Add your FTP server details to your .env file:
FTP_DEPLOY_HOST=ftp.example.com FTP_DEPLOY_USERNAME=your_username FTP_DEPLOY_PASSWORD=your_password FTP_DEPLOY_PORT=21 FTP_DEPLOY_SSL=false FTP_DEPLOY_ROOT=/public_html FTP_DEPLOY_TAG=deployed-latest
Usage
Run the deployment command:
php artisan deploy:ftp
Command Options
| Option | Description |
|---|---|
--all |
Deploy all tracked files (useful for initial deployment) |
--status |
Deploy modified and untracked files based on git status |
--from=COMMIT |
Starting Git commit or tag reference to diff from |
--to=COMMIT |
Ending Git commit (defaults to HEAD) |
--dry-run |
Print list of files that would be uploaded without connecting/uploading |
--host=HOST |
Override FTP host |
--user=USER |
Override FTP username |
--password=PASS |
Override FTP password |
--port=PORT |
Override FTP port (default: 21) |
--ssl |
Connect using SSL/TLS (FTPS) |
--root=PATH |
FTP remote root folder (e.g. /public_html) |
--tag=TAG |
Git tag to track the last deployed commit (default: deployed-latest) |
--push |
Push the deployment Git tag to remote Git origin |
--exclude=PATH |
Comma-separated list of additional files/directories to exclude |
Examples
Simulate a full deployment (Dry Run):
php artisan deploy:ftp --all --dry-run
Deploy uncommitted / modified files from git status:
php artisan deploy:ftp --status
Deploy diff between HEAD~2 and HEAD:
php artisan deploy:ftp --from=HEAD~2 --to=HEAD
License
The MIT License (MIT). Please see License File for more information.