You can start a new Laravel project without installing PHP, Composer, or Node.js on your local machine. By using Docker, your local environment stays clean.
Here is how to create a fresh Laravel application using a temporary container.
Prerequisites
Before we start, you’ll need a container runtime. You can install either:
- OrbStack: Highly recommended for macOS users as it’s lightning fast and lightweight.
- Docker Desktop: The standard Docker environment.
(A quick heads-up: don’t forget to actually open Docker or OrbStack before running the commands below we’ve all been there!)
Step 1: Bootstrapping with a Composer Container
Instead of installing Composer globally on your machine, we’ll spin up an ephemeral Composer container and drop into its shell. This container will give us an isolated sandbox to scaffold our project. We will be using the official Composer Docker image to achieve this.
Run the following command in your terminal:
docker run --rm -it \
-v "$(pwd):/app" \
-w /app \
composer:latest \
sh
This mounts your current directory into the container at /app and opens an interactive shell.
Step 2: Installing the Laravel Installer
Now that we’re inside the container, let’s install the official Laravel installer globally:
composer global require laravel/installer
Next, we need to add the global Composer binary directory to our environment’s path so we can run the laravel command:
export PATH="$PATH:/tmp/vendor/bin"
Let’s verify everything is working by checking the version:
laravel --version
Step 3: Creating the Application
Now we can create our new application. Just replace <app-name> with your desired project name:
laravel new <app-name>
During this process, Laravel will prompt you to choose a starter kit (like Breeze or Jetstream) and testing framework. Feel free to choose whatever fits your needs!
Note: During the installation, the npm or frontend-related steps might fail. Don’t worry! This is completely normal because our minimal Composer container doesn’t include Node.js. We’ll handle our frontend assets later using Laravel Sail.
Step 4: Setting up Laravel Sail
Move into your newly created project directory:
cd <app-name>
Now, let’s pull in Laravel Sail, which provides a great local development experience using Docker:
composer require laravel/sail --dev
php artisan sail:install
Follow the prompts to select the services you want (like MySQL, Redis, etc.). Once the installation completes, our work inside the temporary Composer container is finished!
Type exit to leave the container shell and return to your local machine:
exit
Step 5: Starting the Application
Back on your local machine, navigate to your project directory if you aren’t there already:
cd <app-name>
Let’s start up our new Laravel environment:
vendor/bin/sail up -d
(Tip: You can add alias sail='vendor/bin/sail' to your shell configuration like .zshrc or .bashrc so you only have to type sail instead of vendor/bin/sail every time!)
Once the containers are running, open a new terminal window or tab to run our migrations and build our frontend assets:
# Run database migrations
vendor/bin/sail artisan migrate
# Install frontend dependencies (you can use npm or bun)
vendor/bin/sail npm install
# or: vendor/bin/sail bun install
# Start the Vite development server
vendor/bin/sail npm run dev
# or: vendor/bin/sail bun run dev
That’s it! Your new Laravel application should now be live at http://localhost.
Bonus: Future-Proofing & AI Development Setup
Since we’re setting up a fresh project, let’s add some excellent tools to keep our codebase clean, modern, and ready for AI-assisted development.
1. AI Development Setup
Let’s prepare the application for AI integration using Laravel Boost. Boost provides a streamlined, AI-ready foundation for your application, helping you to rapidly scaffold and build features with AI assistance. You can learn more about it on the official Laravel Boost repository.
Also, be sure to check out the Laravel AI SDK. It gives you the power to build complete AI‑native applications in a single first‑party package!
vendor/bin/sail composer require laravel/boost --dev
vendor/bin/sail artisan boost:install
2. Automatic Formatting with Laravel Pint
To keep our code style consistent without the headache, we can use Laravel Pint. Pint is an officially supported, opinionated PHP code style fixer for minimalists built on top of PHP-CS-Fixer. It ensures your code is always clean and adheres strictly to Laravel’s standards.
vendor/bin/sail composer require laravel/pint --dev
# Run it anytime to format your code:
vendor/bin/sail pint
3. Future-Proofing with Rector
Rector automatically upgrades your PHP code and helps you leverage the latest features and best practices.
First, let’s install Rector and its Laravel extensions:
vendor/bin/sail composer require rector/rector --dev
vendor/bin/sail composer require --dev driftingly/rector-laravel
Next, create a rector.php file in the root of your project with this configuration:
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use RectorLaravel\Set\LaravelLevelSetList;
return RectorConfig::configure()
->withPaths([
__DIR__ . '/app',
__DIR__ . '/bootstrap',
__DIR__ . '/config',
__DIR__ . '/public',
__DIR__ . '/resources',
__DIR__ . '/routes',
__DIR__ . '/tests',
])
->withPhpSets()
->withSets([
LaravelLevelSetList::UP_TO_LARAVEL_130,
])
->withTypeCoverageLevel(0)
->withDeadCodeLevel(0)
->withCodeQualityLevel(0);
Whenever you want to process and automatically upgrade your codebase, simply run:
vendor/bin/sail php vendor/bin/rector process
To learn more about what rules you can apply and how to customize your rector.php file further, be sure to check out the official Rector documentation.
You now have a clean Laravel setup running in Docker, complete with code formatting and AI-ready tools.
Deployment Options
When you’re ready to share your creation with the world, Laravel provides some fantastic, first-party options tailored specifically for the framework:
- Laravel Cloud: The fastest way to deploy and scale Laravel applications without managing servers, featuring one-click autoscaling, databases, caching, and storage.
- Laravel Forge: Perfect for managing traditional VPS servers (like DigitalOcean, Linode, AWS, etc.) without the headache.
- Laravel Vapor: A robust serverless deployment platform powered by AWS. (Personal note: I’ve been using Vapor for ages and it works amazingly well no affiliate link here, just genuine appreciation!)