网页 综合 更新时间 2026-11-13 17:32:33

Laravel Sail | Laravel 13.x - The clean stack for Artisans and agents

自动蜘蛛 laravel.com 正文约 6000 字
Laravel Sail | Laravel 13.x - The clean stack for Artisans and agents
Laravel Sail is a light-weight command-line interface for interacting with Laravel's default Docker development environment. Sail provides a great starting point for building a Laravel application using PHP, MySQL, and Redis without requiring prior Docker experience.
At its heart, Sail is the compose.yaml file and the sail script that is stored at the root of your project. The sail script provides a CLI with convenient methods for interacting with the Docker containers defined by the compose.yaml file.
Laravel Sail is supported on macOS, Linux, and Windows (via WSL2).
You may install Sail using the Composer package manager:
After Sail has been installed, you may run the sail:install Artisan command. This command will publish Sail's compose.yaml file to the root of your application and modify your .env file with the required environment variables in order to connect to the Docker services:
Finally, you may start Sail. To continue learning how to use Sail, please continue reading the remainder of this documentation:
If you are using Docker Desktop for Linux, you should use the default Docker context by executing the following command: docker context use default. In addition, if you encounter file permission errors within containers, you may need to set the SUPERVISOR_PHP_USER environment variable to root.
If you would like to add an additional service to your existing Sail installation, you may run the sail:add Artisan command:
If you would like to develop within a Devcontainer, you may provide the --devcontainer option to the sail:install command. The --devcontainer option will instruct the sail:install command to publish a default .devcontainer/devcontainer.json file to the root of your application:
Sometimes you may want to completely rebuild your Sail images to ensure all of the image's packages and software are up to date. You may accomplish this using the build command:
By default, Sail commands are invoked using the vendor/bin/sail script that is included with all new Laravel applications:
However, instead of repeatedly typing vendor/bin/sail to execute Sail commands, you may wish to configure a shell alias that allows you to execute Sail's commands more easily:
To make sure this is always available, you may add this to your shell configuration file in your home directory, such as ~/.zshrc or ~/.bashrc, and then restart your shell.
Once the shell alias has been configured, you may execute Sail commands by simply typing sail. The remainder of this documentation's examples will assume that you have configured this alias:
Laravel Sail's compose.yaml file defines a variety of Docker containers that work together to help you build Laravel applications. Each of these containers is an entry within the services configuration of your compose.yaml file. The laravel.test container is the primary application container that will be serving your application.
Before starting Sail, you should ensure that no other web servers or databases are running on your local computer. To start all of the Docker containers defined in your application's compose.yaml file, you should execute the up command:
To start all of the Docker containers in the background, you may start Sail in "detached" mode:
Once the application's containers have been started, you may access the project in your web browser at: http://localhost.
To stop all of the containers, you may simply press Control + C to stop the container's execution. Or, if the containers are running in the background, you may use the stop command:
When using Laravel Sail, your application is executing within a Docker container and is isolated from your local computer. However, Sail provides a convenient way to run various commands against your application such as arbitrary PHP commands, Artisan commands, Composer commands, and Node / NPM commands.
When reading the Laravel documentation, you will often see references to Composer, Artisan, and Node / NPM commands that do not reference Sail. Those examples assume that these tools are installed on your local computer. If you are using Sail for your local Laravel development environment, you should execute those commands using Sail:
PHP commands may be executed using the php command. Of course, these commands will execute using the PHP version that is configured for your application. To learn more about the PHP versions available to Laravel Sail, consult the PHP version documentation:
Composer commands may be executed using the composer command. Laravel Sail's application container includes a Composer installation:
Laravel Artisan commands may be executed using the artisan command:
Node commands may be executed using the node command while NPM commands may be executed using the npm command:
If you wish, you may use Yarn instead of NPM:
As you may have noticed, your application's compose.yaml file contains an entry for a MySQL container. This container uses a Docker volume so that the data stored in your database is persisted even when stopping and restarting your containers.
In addition, the first time the MySQL container starts, it will create two databases for you. The first database is named using the value of your DB_DATABASE environment variable and is for your local development. The second is a dedicated testing database named testing and will ensure that your tests do not interfere with your development data.
Once you have started your containers, you may connect to the MySQL instance within your application by setting your DB_HOST environment variable within your application's .env file to mysql.
To connect to your application's MySQL database from your local machine, you may use a graphical database management application such as TablePlus. By default, the MySQL database is accessible at localhost port 3306 and the access credentials correspond to the values of your DB_USERNAME and DB_PASSWORD environment variables. Or, you may connect as the root user, which also utilizes the value of your DB_PASSWORD envi
访问原文 返回搜索 https://laravel.com/framework/docs/sail
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。