Skip to content

Easily sync server (production/staging) database and files to your local environment

License

Notifications You must be signed in to change notification settings

ajaxray/laravel-server-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Server Sync

Latest Version on Packagist Total Downloads License

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.

Laravel Server Sync Banner

Features

  • πŸ”„ 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

Requirements

  • 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

Installation

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"

Configuration

Environment Variables

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

Configuration File

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

Usage

Basic Usage

Sync both database and files:

php artisan sync:pull

Database Sync Options

# 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

File Sync Options

# 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

Server Configuration Options

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 

Safety Features

# 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.

Security

  • Uses SSH for secure file transfer
  • Requires key-based authentication
  • Temporary files are automatically cleaned up
  • Database credentials are never stored locally

Troubleshooting

SSH Connection Issues

  • Verify SSH key-based authentication is set up
  • Check if you can manually SSH into the server
  • Ensure proper permissions for the SSH user

Database Sync Issues

  • Verify MySQL client installation
  • Check database credentials in both environments
  • Ensure sufficient privileges for database operations

File Sync Issues

  • Verify rsync installation
  • Check storage directory permissions
  • Use stable internet connection for large files

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Easily sync server (production/staging) database and files to your local environment

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages