A Laravel package to easily sync your production/staging database and storage files to your local environment. Perfect for debugging production issues or keeping your local environment up to date with production data.
Note: This package is now stable and ready for production use. It supports Laravel 10.x and 11.x.
- π One-command sync of both database and files
- π Secure SSH-based file transfer
- π Smart file syncing with rsync
- ποΈ Database dump and restore
- β‘ Progress indicators for long operations
- π οΈ Highly configurable
- PHP 8.1 or higher
- Laravel 10.0 or higher
- SSH access to production server
- MySQL/MariaDB client installed locally
- rsync installed on both local and production servers
composer require ajaxray/laravel-server-sync
To install for dev environments
composer require --dev ajaxray/laravel-server-sync
After installation, publish the configuration file:
php artisan vendor:publish --provider="Ajaxray\ServerSync\ServerSyncServiceProvider"
Add these to your .env
file:
PROD_SSH_HOST=your-production-server.com
PROD_SSH_USER=your-ssh-username
PROD_SSH_PATH=/path/to/laravel
The published config file config/server-sync.php
allows you to:
- Configure default server settings
- Exclude specific tables from database sync
- Configure file sync paths and exclusions
- Customize dump location
Sync both database and files:
php artisan sync:pull
# Skip database sync entirely
php artisan sync:pull --skip-db
# Exclude specific tables
php artisan sync:pull --exclude-tables=logs,cache,sessions
# Only sync specific tables
php artisan sync:pull --only-tables=users,products,orders
# Skip file sync entirely
php artisan sync:pull --skip-files
# Sync files with deletion (removes local files that don't exist in production)
php artisan sync:pull --delete
By default, it'll take host, user, path etc. from the production server definition in config file.
Also we can specify which remote server definition to use (see config file), if we have defined multiple servers. If any config is specified as inline option, it'll get precidence over config values.
php artisan sync:pull --remote=staging
# Override server details inline
php artisan sync:pull --host=prod.example.com --user=deploy --path=/var/www/app
# All options can be specified inline to overwrite config values
php artisan sync:pull --host=prod.example.com --user=deploy --exclude-tables=logs,migrations
# Force sync in production environment (use with caution!)
php artisan sync:pull --force
Note: The
--force
option should be used with extreme caution as it overrides the production environment safety check.
- Uses SSH for secure file transfer
- Requires key-based authentication
- Temporary files are automatically cleaned up
- Database credentials are never stored locally
- Verify SSH key-based authentication is set up
- Check if you can manually SSH into the server
- Ensure proper permissions for the SSH user
- Verify MySQL client installation
- Check database credentials in both environments
- Ensure sufficient privileges for database operations
- Verify rsync installation
- Check storage directory permissions
- Use stable internet connection for large files
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.