PHPackages                             subhanraj/laravel-db-provisioner - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. subhanraj/laravel-db-provisioner

ActiveLibrary[Database &amp; ORM](/categories/database)

subhanraj/laravel-db-provisioner
================================

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

v1.0.5(1w ago)01↓100%MITPHPPHP ^8.1

Since May 29Pushed 1w agoCompare

[ Source](https://github.com/SubhanRaj/laravel-db-provisioner)[ Packagist](https://packagist.org/packages/subhanraj/laravel-db-provisioner)[ RSS](/packages/subhanraj-laravel-db-provisioner/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (2)Versions (7)Used By (0)

Laravel DB Provisioner
======================

[](#laravel-db-provisioner)

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

[](#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
------------

[](#installation)

### Via Composer

[](#via-composer)

```
composer require subhanraj/laravel-db-provisioner
```

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

Usage
-----

[](#usage)

After installation, run:

```
php artisan db:provision
```

### What the command does:

[](#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

[](#next-steps)

After running the command, execute:

```
php artisan key:generate
php artisan migrate
```

Configuration Requirements
--------------------------

[](#configuration-requirements)

### MySQL/MariaDB Server

[](#mysqlmariadb-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

[](#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

[](#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
--------------

[](#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
---------------

[](#troubleshooting)

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

[](#failed-to-connect-to-hostport)

- 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'"

[](#access-denied-for-user-root127001)

- 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"

[](#envexample-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"

[](#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

[](#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
-------

[](#license)

MIT

Support
-------

[](#support)

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

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance98

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

6

Last Release

11d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d7c1aa91263a2c5b1ed9bc4233205aa2907cdacbb3afcc4eaf09d666bd42610?d=identicon)[SubhanRaj](/maintainers/SubhanRaj)

---

Top Contributors

[![SubhanRaj](https://avatars.githubusercontent.com/u/46089881?v=4)](https://github.com/SubhanRaj "SubhanRaj (1 commits)")

---

Tags

laraveldatabasedevelopmentprovisioningsetup

### Embed Badge

![Health badge](/badges/subhanraj-laravel-db-provisioner/health.svg)

```
[![Health](https://phpackages.com/badges/subhanraj-laravel-db-provisioner/health.svg)](https://phpackages.com/packages/subhanraj-laravel-db-provisioner)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k54.1M11.0k](/packages/illuminate-database)[laravel/ai

The official AI SDK for Laravel.

9782.1M153](/packages/laravel-ai)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

436834.4k1](/packages/clickbar-laravel-magellan)[itpathsolutions/dbstan

Database Standardization and Analysis Tool for Laravel

442.1k](/packages/itpathsolutions-dbstan)[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

166219.6k1](/packages/cybercog-laravel-clickhouse)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3359.7k2](/packages/toponepercent-baum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
