subhanraj/laravel-db-provisioner

Automate local database and user creation with a single Artisan command for Laravel

Maintainers

Package info

github.com/SubhanRaj/laravel-db-provisioner

pkg:composer/subhanraj/laravel-db-provisioner

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.5 2026-05-29 17:10 UTC

This package is auto-updated.

Last update: 2026-05-29 17:20:52 UTC


README

A Laravel package that automates local database and user creation for new project clones. Perfect for any local development environment (Valet, XAMPP, Laragon, Homebrew, Docker Compose, etc.) using MySQL or MariaDB.

Features

  • 🔧 Automatic .env file creation from .env.example
  • 🔐 Generates secure 16-character database passwords
  • 📝 Auto-generates database names from your APP_NAME or directory name
  • 🗄️ Creates database, users, and grants privileges via raw PDO
  • 💻 Works with any MySQL/MariaDB setup (XAMPP, Laragon, Valet, Homebrew, etc.)
  • 🪟 Cross-platform: Windows, macOS, Linux
  • ⚡ Single command setup: php artisan db:provision

Installation

Via Composer

composer require subhanraj/laravel-db-provisioner

The package will auto-register via Laravel's package discovery.

Usage

After installation, run:

php artisan db:provision

What the command does:

  1. ✓ Checks if .env exists; copies from .env.example if needed

  2. ✓ Generates a clean database name (e.g., myapp_local)

  3. ✓ Generates a secure 16-character password

  4. ✓ Updates .env with DB_DATABASE, DB_USERNAME, and DB_PASSWORD

  5. ✓ Prompts for database admin username (defaults to root)

  6. ✓ Prompts for database admin password (allows blank for no-password setups)

  7. ✓ Connects to your database using the provided credentials and executes:

    • CREATE DATABASE IF NOT EXISTS {DB_DATABASE}
    • Creates database users for both 127.0.0.1 and localhost
    • Grants all privileges on the database to those users
    • Flushes privileges
  8. ✓ Outputs a success message with the new credentials

Next Steps

After running the command, execute:

php artisan key:generate
php artisan migrate

Configuration Requirements

MySQL/MariaDB Server

This package requires a running MySQL or MariaDB server. The package will:

  • Use the database host and port from your .env file (defaults to 127.0.0.1:3306)
  • Prompt for the admin username (defaults to root)
  • Accept blank passwords for no-password setups (common in local development)

Supported Environments

This package works with any local MySQL/MariaDB setup:

  • XAMPP - Uses root user with no password by default
  • Laragon - Uses root user with no password by default
  • Laravel Valet - Works with MySQL/MariaDB started via Valet
  • Homebrew - Works with Homebrew-installed MySQL/MariaDB
  • Docker Compose - Works with containers if the host is accessible
  • Windows Subsystem for Linux (WSL) - Works with any WSL database setup

Environment Variables

The package reads and modifies the following .env variables:

DB_CONNECTION=mysql        # Connection type (mysql or mariadb)
DB_HOST=127.0.0.1         # Database host (customizable, defaults to 127.0.0.1)
DB_PORT=3306              # Database port (customizable, defaults to 3306)
DB_DATABASE=              # Generated by command
DB_USERNAME=              # Generated by command (same as DB_DATABASE)
DB_PASSWORD=              # Generated securely (16 chars)

Security Notes

  • Passwords are generated with a mix of uppercase, lowercase, numbers, and special characters
  • Uses file_get_contents() and preg_replace() for safe .env file updates
  • Raw PDO connection ensures no Laravel query builder interference
  • Admin credentials are taken as input (not stored) and used only for database setup
  • After provisioning, the command disconnects from the admin account

Troubleshooting

"Failed to connect to [host]:[port]"

  • Ensure your database server is running
    • XAMPP: Check Apache/MySQL in Control Panel
    • Laragon: Check Laragon is running
    • Valet: Ensure MySQL is started (valet use mysql or equivalent)
    • Homebrew: brew services list | grep mysql or brew services list | grep mariadb
  • Verify the DB_HOST and DB_PORT in your .env file match your setup
  • Check that your firewall isn't blocking the connection

"Access denied for user 'root'@'127.0.0.1'"

  • Verify you entered the correct admin username and password
  • For XAMPP/Laragon: Default is usually root with no password (leave blank when prompted)
  • For Homebrew: If you ran mysql_secure_installation, use the password you set
  • Try connecting manually: mysql -h 127.0.0.1 -u root -p

".env.example file not found"

  • Ensure your Laravel project has a .env.example file in the root
  • Create one from your .env if needed: cp .env .env.example

"Permission denied" or "GRANT failed"

  • Ensure the admin user has privileges to create users and databases
  • Try connecting manually to verify admin access works
  • Check your database server logs for detailed error messages

Command hangs or times out

  • Your database server may not be responding
  • Check your firewall/antivirus isn't blocking connections
  • Try connecting manually first to isolate the issue

License

MIT

Support

For issues, questions, or contributions, please open an issue on GitHub or see CONTRIBUTING.md.