When creating a new Laravel application via Sail, you may use the with
query string variable to choose which services should be configured in your new application's docker-compose.yml
file. Available services include mysql
, pgsql
, mariadb
, redis
, memcached
, meilisearch
, minio
, selenium
, and mailhog
:
curl -s "https://laravel.build/example-app?with=mysql,redis" | bash
If you do not specify which services you would like configured, a default stack of mysql
, redis
, meilisearch
, mailhog
, and selenium
will be configured.
Installation Via Composer
If your computer already has PHP and Composer installed, you may create a new Laravel project by using Composer directly. After the application has been created, you may start Laravel's local development server using the Artisan CLI's serve
command:
composer create-project laravel/laravel example-app
cd example-app
php artisan serve
The Laravel Installer
Or, you may install the Laravel Installer as a global Composer dependency:
composer global require laravel/installer
laravel new example-app
cd example-app
php artisan serve
Make sure to place Composer's system-wide vendor bin directory in your $PATH
so the laravel
executable can be located by your system. This directory exists in different locations based on your operating system; however, some common locations include:
- macOS:
$HOME/.composer/vendor/bin
- Windows:
%USERPROFILE%\AppData\Roaming\Composer\vendor\bin
- GNU / Linux Distributions:
$HOME/.config/composer/vendor/bin
or$HOME/.composer/vendor/bin
For convenience, the Laravel installer can also create a Git repository for your new project. To indicate that you want a Git repository to be created, pass the --git
flag when creating a new project:
laravel new example-app --git
This command will initialize a new Git repository for your project and automatically commit the base Laravel skeleton. The git
flag assumes you have properly installed and configured Git. You can also use the --branch
flag to set the initial branch name:
laravel new example-app --git --branch="main"
Instead of using the --git
flag, you may also use the --github
flag to create a Git repository and also create a corresponding private repository on GitHub:
laravel new example-app --github
The created repository will then be available at https://github.com/<your-account>/example-app
. The github
flag assumes you have properly installed the GitHub CLI and are authenticated with GitHub. Additionally, you should have git
installed and properly configured. If needed, you can pass additional flags that are supported by the GitHub CLI:
laravel new example-app --github="--public"
You may use the --organization
flag to create the repository under a specific GitHub organization:
laravel new example-app --github="--public" --organization="laravel"
Initial Configuration
All of the configuration files for the Laravel framework are stored in the config
directory. Each option is documented, so feel free to look through the files and get familiar with the options available to you.
Laravel needs almost no additional configuration out of the box. You are free to get started developing! However, you may wish to review the config/app.php
file and its documentation. It contains several options such as timezone
and locale
that you may wish to change according to your application.
Environment Based Configuration
Since many of Laravel's configuration option values may vary depending on whether your application is running on your local computer or on a production web server, many important configuration values are defined using the .env
file that exists at the root of your application.
Your .env
file should not be committed to your application's source control, since each developer / server using your application could require a different environment configuration. Furthermore, this would be a security risk in the event an intruder gains access to your source control repository, since any sensitive credentials would get exposed.
For more information about the
.env
file and environment based configuration, check out the full configuration documentation.
Directory Configuration
Laravel should always be served out of the root of the "web directory" configured for your web server. You should not attempt to serve a Laravel application out of a subdirectory of the "web directory". Attempting to do so could expose sensitive files that exist within your application.
Next Steps
Now that you have created your Laravel project, you may be wondering what to learn next. First, we strongly recommend becoming familiar with how Laravel works by reading the following documentation:
How you want to use Laravel will also dictate the next steps on your journey. There are a variety of ways to use Laravel, and we'll explore two primary use cases for the framework below.
Laravel The Full Stack Framework
Laravel may serve as a full stack framework. By "full stack" framework we mean that you are going to use Laravel to route requests to your application and render your frontend via Blade templates or using a single-page application hybrid technology like Inertia.js. This is the most common way to use the Laravel framework.
If this is how you plan to use Laravel, you may want to check out our documentation on routing, views, or the Eloquent ORM. In addition, you might be interested in learning about community packages like Livewire and Inertia.js. These packages allow you to use Laravel as a full-stack framework while enjoying many of the UI benefits provided by single-page JavaScript applications.
If you are using Laravel as a full stack framework, we also strongly encourage you to learn how to compile your application's CSS and JavaScript using Laravel Mix.
If you want to get a head start building your application, check out one of our official application starter kits.
Laravel The API Backend
Laravel may also serve as an API backend to a JavaScript single-page application or mobile application. For example, you might use Laravel as an API backend for your Next.js application. In this context, you may use Laravel to provide authentication and data storage / retrieval for your application, while also taking advantage of Laravel's powerful services such as queues, emails, notifications, and more.
If this is how you plan to use Laravel, you may want to check out our documentation on routing, Laravel Sanctum, and the Eloquent ORM.
0 Comments