daiyan_mozumder / flex-db-dump
Laravel database backup & download package with SQL dump or PHP-only exporter
Requires
- php: >=8.1
- illuminate/support: ^10|^11|^12
README
Laravel database backup & download package with mysqldump or PHP-only exporter.
Features
- SQL dump (CLI)
- PHP-only exporter (shared hosting friendly)
- Config based mode switching
- Chunked export
- Auto download
- Secure & lightweight
Installation
composer require daiyan_mozumder/flex-db-dump
Configuration
FLEX_DB_DUMP_MODE=php
Configuring mysqldump path
flex-db-dump uses mysqldump to create database backups. By default, it tries to run mysqldump from the system PATH. Depending on your environment, you may need to explicitly set the path.
Step 1: Publish the config
Publish Config
php artisan vendor:publish --tag=flex-db-dump-config
This will create:
config/flex_db_dump.php
Step 2: Update the mysqldump_path
Open config/flex_db_dump.php:
return [ // Backup storage path 'path' => storage_path('app/db_backups'), // Full path to mysqldump executable 'mysqldump_path' => env('MYSQLDUMP_PATH', 'mysqldump'), // default ];
Step 3: Set environment variable in .env
1️⃣ Local development
Windows (XAMPP, WAMP):
MYSQLDUMP_PATH="C:\\xampp\\mysql\\bin\\mysqldump.exe"
Linux/macOS:
MYSQLDUMP_PATH="/usr/bin/mysqldump"
You can test the path in terminal:
C:\xampp\mysql\bin\mysqldump.exe --version # Windows /usr/bin/mysqldump --version # Linux
2️⃣ VPS / Shared Hosting
On VPS with shell access:
MYSQLDUMP_PATH="/usr/bin/mysqldump"
On shared hosting:
- Check if mysqldump is available:
which mysqldump
- Use the full path returned:
MYSQLDUMP_PATH="/usr/local/mysql/bin/mysqldump"
Supported modes:
php → No CLI, pure PHP
sql → Uses mysqldump
Route
GET /flex/db-dump
Protect it:
Route::middleware(['auth', 'role:admin'])->group(...)
Usage
Visit:
/flex/db-dump
Your database will download automatically.
Requirements
PHP 8.1+ Laravel 10+ mysqldump (for sql mode)
Security
⚠️ Always restrict route access (admin only).
🖥 Server Requirements for mysqldump Mode (VPS / VFS)
When using sql mode, flex-db-dump relies on the system-level mysqldump binary. This does NOT work automatically unless your server is properly configured.
✅ Supported Server Types
- VPS (DigitalOcean, AWS EC2, Hetzner, Linode, etc.)
- Dedicated server
- Docker-based servers
- Self-managed cloud servers
⚠️ Not supported on most shared hosting environments.
1️⃣ Verify mysqldump Is Installed
Run this on your server:
Windows:
mysqldump --version
Expected output:
mysqldump Ver 8.0.30 for Win64 on x86_64 (MySQL Community Server - GPL)
MacOS
which mysqldump
Expected output:
/usr/bin/mysqldump
If nothing is returned, install it.
2️⃣ Install MySQL Client (If Missing)
Ubuntu / Debian
sudo apt update
sudo apt install mysql-client -y
CentOS / Rocky / Alma
sudo yum install mysql -y
3️⃣ Ensure PHP Can Execute System Commands
The following PHP functions must NOT be disabled:
- proc_open
- shell_exec
- exec
Check:
php -i | grep disable_functions
If disabled, update php.ini:
disable_functions =
Then restart PHP:
sudo systemctl restart php8.2-fpm
4️⃣ MySQL Credentials Access (IMPORTANT)
Option A: Use Laravel .env (Default)
DB_HOST=127.0.0.1 DB_DATABASE=your_db DB_USERNAME=your_user DB_PASSWORD=your_password
⚠️ Some MySQL versions block passwords passed via CLI.
Option B (RECOMMENDED): Use .my.cnf (Most Secure)
Create this file:
nano ~/.my.cnf
Add:
[mysqldump]
user=your_db_user password=your_db_password host=127.0.0.1
Set permissions:
chmod 600 ~/.my.cnf
Then remove password from CLI usage automatically — mysqldump will read it securely.
✅ This avoids password exposure in process lists.
5️⃣ SELinux (CentOS Only)
If SELinux is enabled:
setsebool -P httpd_can_network_connect_db 1
6️⃣ Storage Permissions
Ensure Laravel can write backups:
chmod -R 775 storage chown -R www-data:www-data storage
7️⃣ Test mysqldump Manually
Before using the package:
mysqldump your_db > test.sql
If this fails, the package will fail too.
8️⃣ Enable SQL Mode in Package
FLEX_DB_DUMP_MODE=sql
9️⃣ When to Use php Mode Instead
Use PHP exporter mode if:
- Shared hosting
- No shell access
- proc_open disabled
- No mysqldump available
FLEX_DB_DUMP_MODE=php
🔐 Security Recommendations
1. Always protect /flex/db-dump route
2. Restrict to admin users only
3. Add rate limiting
4. Never expose publicly
Example:
Route::middleware(['auth', 'role:admin', 'throttle:1,10'])->group(function () { Route::get('flex/db-dump', [\Flex\DbDump\Http\Controllers\DbDumpController::class, 'download']); })->name('flex_db_dump');
Author
Daiyan Mozumder
License
MIT