Creating a New Laravel Project

There are three ways to create a new Laravel project, each of which are run from the command line. The first option is to globally install the Laravel installer tool (using Composer); the second is to use Composer’s create-project feature; and the third is to create your project together with a Docker-based Laravel tool called Sail.

You can learn about each option in greater detail on the Installation documentation page, but I’d recommend the Laravel installer tool; it sets you up in the most common workflow among Laravel develoeprs, and helps you install common first-party dependencies as you go.

If you want the simplest option for creating a new Laravel application, that’s Composer’s create-project feature, which focuses on creating new PHP-based with a particular skeleton. To use this tool to create a new Laravel project, issue the following command:

composer create-project laravel/laravel projectName

This will create a subdirectory of your current directory named {projectName} that contains a skeleton Laravel install, ready for you to develop.

Installing Laravel with the Laravel Installer Tool

The Laravel installer tool is much more robust than Composer’s create-project feature, as it walks you through an entire installation process, adding starter kits, initializing Git repositories, and more.

If you have Composer installed globally, installing the Laravel installer tool is as simple as running the following command:

composer global require "laravel/installer"

Once you have the Laravel installer tool installed, you can spin up a new Laravel site with this command:

laravel new projectName

This will create a new subdirectory of your current directory named {projectName} and install a Laravel project in it. But first, you’ll walk through a series of questions about how you want to proceed. You’ll learn more about how to answer these questions later, but for now, I’d recommend you choose the following defaults:

  • Would you like to install a starter kit? Laravel Breeze
  • Which Breeze stack would you like to install? Blade with Alpine
  • Would you like dark mode support? Your choice!
  • Which testing framework do you prefer? PHPUnit
  • Would you like to initialize a Git repository? Yes
  • Which database will your application use? SQLite

One quick note — ​I recommended you choose PHPUnit as the testing framework not because it’s better than Pest, but because Pest is new enough that most testing resources on the Internet still teach you about PHPUnit-style tests, so I’d recommend that for a beginner. If you’re interested in learning Pest instead, go for it! It’s my preferred testing tool.

Installing Laravel with Sail

If you plan to work with Laravel Sail, you can install a Laravel app and begin its Sail installation process at the same time. Ensure you have Docker installed on your computer, and then issue the following command, replacing example-app with the name of your app:

curl -s "https://laravel.build/example-app" | bash

This will install Laravel into the example-app folder underneath your current folder and then begin the Sail installation process.

Once that installation process is complete, change to your new directory and spin up Sail:

cd example-app
./vendor/bin/sail up

Note

The first time you run sail up, it’ll take quite a bit longer than other installation processes, as it needs to build up the initial Docker image.


Creating a New Laravel Project was originally published in Javarevisited on Medium, where people are continuing the conversation by highlighting and responding to this story.

This post first appeared on Read More