ホーム > Laravel > Installing Laravel in the Current Directory with 'laravel new' Seems Impossible [Alternative Solutions Included]
Laravel

Installing Laravel in the Current Directory with 'laravel new' Seems Impossible [Alternative Solutions Included]

Thank you for your continued support.
This article contains advertisements that help fund our operations.

I explored alternative ways to install Laravel in the current directory since it seems impossible with the `laravel new` command.

Introduction

When creating a new Laravel project, you might want to set up a directory structure, for example, with Docker:

ProjectName
├── docker/
├── src/
└── docker-compose.yml

In such cases, you might want to install the Laravel project inside the src directory. It would be convenient if you could install it directly in the current directory.

It's Probably Not Possible with laravel new

Methods I Tried

Without Specifying a Project Name

laravel new

When prompted to enter a project name, inputting:

.

results in:

Application already exists.

Using .

laravel new .

Results in the following error:

Application already exists!

Using --force

laravel new --force

When prompted to enter a project name, it results in:

Cannot use --force option when using current directory for installation!

It Seems Impossible

This issue has also been discussed on Laracasts without a clear resolution for using laravel new:

Laracasts - Install Laravel to an existing folder

Alternative Solutions

Here are two alternative methods:

  1. Use Composer to install Laravel.
  2. Install Laravel in a temporary directory and move it.

Using Composer

composer create-project laravel/laravel:^11.0 .

This command installs a Laravel project in the current directory, but it does not offer the starter kit selection provided by laravel new.

 ┌ Would you like to install a starter kit? ────────────────────┐
 │ › ● No starter kit                                           │
 │   ○ Laravel Breeze                                           │
 │   ○ Laravel Jetstream

However, you can manually install a starter kit afterward, and the rest of the workflow remains the same.

Breeze

composer require laravel/breeze --dev
php artisan breeze:install

Laravel 11.x Starter Kits

Jetstream

composer require laravel/jetstream
php artisan jetstream:install

Laravel Jetstream - Installation

Installing in a Temporary Directory and Moving Files

While not ideal, you can install Laravel in a temporary directory:

laravel new src

This will result in the following structure:

ProjectName
    ├── docker/
    ├── src/src/ [files and folders installed here]
    └── docker-compose.yml

You can then move all files and folders from the nested src/src/ directory to the desired src/ directory.

Conclusion

I hope this helps someone looking for solutions to this issue!

Please Provide Feedback
We would appreciate your feedback on this article. Feel free to leave a comment on any relevant YouTube video or reach out through the contact form. Thank you!