laravel/installer
Laravel Installer is the official command-line tool for creating new Laravel applications. Install globally via Composer and run laravel new to scaffold a fresh project quickly, with the latest framework version and starter setup.
Installation:
composer global require laravel/installer
Ensure ~/.composer/vendor/bin is in your PATH.
First Use Case: Create a new Laravel project in a directory:
laravel new project-name
This clones the Laravel repository, installs dependencies, and sets up the project structure.
Key Flags:
--preset=api: Generate an API-focused project.--stack=jetstream: Use Jetstream scaffolding.--database=sqlite: Specify a database (auto-runs migrations).--no-interaction: Skip prompts (useful for CI/CD).Where to Look First:
laravel --help for CLI options.Local Development Setup:
laravel new my-app --preset=api --database=mysql
cd my-app
cp .env.example .env
composer install
php artisan key:generate
--preset to tailor the project (e.g., api, jetstream, fortify).--stack for frontend frameworks (e.g., --stack=inertia).CI/CD Integration:
laravel new my-app --no-interaction --preset=api --database=postgres
--no-interaction to avoid prompts in automated pipelines.Custom Starter Kits:
laravel new my-app --kit=git@github.com:user/custom-kit.git
--kit to use custom templates (e.g., monorepos, legacy setups).Database Handling:
laravel new my-app --database=sqlite --force
--database=mysql --force with pre-configured .env).Environment-Specific Flags:
--no-boost to skip Laravel Boost installation if not needed.valet/herd for local development (installer auto-detects and suggests).composer.json:
"scripts": {
"post-install-cmd": [
"@php artisan key:generate",
"@php artisan config:clear"
]
}
--hook flag (v5.28.0+) to run custom scripts after installation:
laravel new my-app --hook="composer require my/package"
~/.laravel/templates/.Path Permissions:
chmod -R 755 /path/to/project
Database Auto-Migration:
--database flag auto-runs migrations, which may fail if:
.env isn’t properly configured (e.g., DB_PASSWORD missing).--force to skip migration prompts or manually run php artisan migrate.Interactive Prompts in CI:
--database=mysql may still prompt for credentials if .env is incomplete..env or use --no-interaction with a pre-configured setup.Laravel Boost Conflicts:
--no-boost flag is required if you’re not using Laravel Boost or have version conflicts.PATH.Custom Kit Issues:
--kit=git@...) require SSH keys or HTTPS credentials.--verbose to see clone errors.Composer Cache:
composer clear-cache
Verbose Output:
laravel new my-app --verbose
Reveals hidden steps (e.g., Git clone URLs, Composer commands).
Dry Run: Simulate installation without changes:
laravel new my-app --dry-run
Log Files:
Check ~/.laravel/logs/ for installer errors (created on failure).
Default Presets:
laravel new my-app --dev
(Uses laravel/framework dev-main branch.)Environment Detection:
valet/herd but may misidentify paths on custom installations.VALET_HOME or HERD_HOME environment variables.Node.js/Package Manager:
npm, yarn, pnpm, and bun. Specify with --npm:
laravel new my-app --npm=yarn
bun may require explicit installation (--npm=bun).PHP Version:
update-alternatives --set php /path/to/php8.2
php -v to confirm the active version.Custom Templates:
Override default templates by copying files from vendor/laravel/installer/src/Stubs/ to ~/.laravel/templates/.
Post-Install Scripts:
Use the --hook flag (v5.28.0+) to run custom commands:
laravel new my-app --hook="php artisan package:discover"
Database Drivers:
Extend supported drivers by modifying the Database class in the installer’s source or using --database=custom with manual setup.
Starter Kit Registry:
Add custom kits to the registry by extending the StarterKit class or using the --kit flag with a Git repo.
CI/CD Optimizations: Cache Composer dependencies and Laravel Boost for faster builds:
composer install --optimize-autoloader --no-dev
How can I help you explore Laravel packages today?