|
| 1 | +# Laravel Server Sync |
| 2 | + |
| 3 | +[](https://packagist.org/packages/ajaxray/laravel-server-sync) |
| 4 | +[](https://packagist.org/packages/ajaxray/laravel-server-sync) |
| 5 | +[](https://packagist.org/packages/ajaxray/laravel-server-sync) |
| 6 | + |
| 7 | +A Laravel package to easily sync your production database and files to your local environment. Perfect for debugging production issues or keeping your local environment up to date with production data. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- 🔄 One-command sync of both database and files |
| 12 | +- 🔒 Secure SSH-based file transfer |
| 13 | +- 📁 Smart file syncing with rsync |
| 14 | +- 🗄️ Database dump and restore |
| 15 | +- ⚡ Progress indicators for long operations |
| 16 | +- 🛠️ Highly configurable |
| 17 | + |
| 18 | +## Requirements |
| 19 | + |
| 20 | +- PHP 8.1 or higher |
| 21 | +- Laravel 10.0 or higher |
| 22 | +- SSH access to production server |
| 23 | +- MySQL/MariaDB client installed locally |
| 24 | +- rsync installed on both local and production servers |
| 25 | + |
| 26 | +## Installation |
| 27 | + |
| 28 | +```bash |
| 29 | +composer require ajaxray/laravel-server-sync |
| 30 | +``` |
| 31 | + |
| 32 | +After installation, publish the configuration file: |
| 33 | + |
| 34 | +```bash |
| 35 | +php artisan vendor:publish --provider="Ajaxray\ServerSync\ServerSyncServiceProvider" |
| 36 | +``` |
| 37 | + |
| 38 | +## Configuration |
| 39 | + |
| 40 | +### Environment Variables |
| 41 | + |
| 42 | +Add these to your `.env` file: |
| 43 | + |
| 44 | +```env |
| 45 | +PROD_SSH_HOST=your-production-server.com |
| 46 | +PROD_SSH_USER=your-ssh-username |
| 47 | +PROD_SSH_PATH=/path/to/laravel |
| 48 | +``` |
| 49 | + |
| 50 | +### Configuration File |
| 51 | + |
| 52 | +The published config file `config/server-sync.php` allows you to: |
| 53 | + |
| 54 | +- Configure default server settings |
| 55 | +- Exclude specific tables from database sync |
| 56 | +- Configure file sync paths and exclusions |
| 57 | +- Customize dump location |
| 58 | + |
| 59 | +## Usage |
| 60 | + |
| 61 | +### Basic Usage |
| 62 | + |
| 63 | +Sync both database and files: |
| 64 | + |
| 65 | +```bash |
| 66 | +php artisan sync:pull |
| 67 | +``` |
| 68 | + |
| 69 | +### Database Sync Options |
| 70 | + |
| 71 | +```bash |
| 72 | +# Skip database sync entirely |
| 73 | +php artisan sync:pull --skip-db |
| 74 | + |
| 75 | +# Exclude specific tables |
| 76 | +php artisan sync:pull --exclude-tables=logs,cache,sessions |
| 77 | + |
| 78 | +# Only sync specific tables |
| 79 | +php artisan sync:pull --only-tables=users,products,orders |
| 80 | +``` |
| 81 | + |
| 82 | +### File Sync Options |
| 83 | + |
| 84 | +```bash |
| 85 | +# Skip file sync entirely |
| 86 | +php artisan sync:pull --skip-files |
| 87 | + |
| 88 | +# Sync files with deletion (removes local files that don't exist in production) |
| 89 | +php artisan sync:pull --delete |
| 90 | +``` |
| 91 | + |
| 92 | +### Server Configuration Options |
| 93 | + |
| 94 | +```bash |
| 95 | +# Override server details inline |
| 96 | +php artisan sync:pull --host=prod.example.com --user=deploy --path=/var/www/app |
| 97 | + |
| 98 | +# All options can be combined |
| 99 | +php artisan sync:pull --host=prod.example.com --user=deploy --exclude-tables=logs --delete |
| 100 | +``` |
| 101 | + |
| 102 | +### Safety Features |
| 103 | + |
| 104 | +```bash |
| 105 | +# Force sync in production environment (use with caution!) |
| 106 | +php artisan sync:pull --force |
| 107 | +``` |
| 108 | + |
| 109 | +> **Note**: The `--force` option should be used with extreme caution as it overrides the production environment safety check. |
| 110 | +
|
| 111 | +## Security |
| 112 | + |
| 113 | +- Uses SSH for secure file transfer |
| 114 | +- Requires key-based authentication |
| 115 | +- Temporary files are automatically cleaned up |
| 116 | +- Database credentials are never stored locally |
| 117 | + |
| 118 | +## Troubleshooting |
| 119 | + |
| 120 | +### SSH Connection Issues |
| 121 | + |
| 122 | +- Verify SSH key-based authentication is set up |
| 123 | +- Check if you can manually SSH into the server |
| 124 | +- Ensure proper permissions for the SSH user |
| 125 | + |
| 126 | +### Database Sync Issues |
| 127 | + |
| 128 | +- Verify MySQL client installation |
| 129 | +- Check database credentials in both environments |
| 130 | +- Ensure sufficient privileges for database operations |
| 131 | + |
| 132 | +### File Sync Issues |
| 133 | + |
| 134 | +- Verify rsync installation |
| 135 | +- Check storage directory permissions |
| 136 | +- Use stable internet connection for large files |
| 137 | + |
| 138 | +## Contributing |
| 139 | + |
| 140 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 141 | + |
| 142 | +## Security Vulnerabilities |
| 143 | + |
| 144 | +Please review [our security policy](../../security/policy) on how to report security vulnerabilities. |
| 145 | + |
| 146 | +## Credits |
| 147 | + |
| 148 | +- [Anis Uddin Ahmad](https://github.com/ajaxray) |
| 149 | +- [All Contributors](../../contributors) |
| 150 | + |
| 151 | +## License |
| 152 | + |
| 153 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments