jamosaur/vali

Docker 运行 Laravel 应用程序

1.3.4 2024-04-29 15:56 UTC

This package is auto-updated.

Last update: 2024-08-29 16:54:02 UTC


README

Latest Version on Packagist Software License Total Downloads

一种简单的方式来在 Laravel 安装中启动 Docker,并支持本地 https。深受 Laravel Sail 启发。

包含的服务

  • nginx + php8.0-fpm
  • mysql 8
  • redis
  • mailhog

要求

  • docker
  • mkcert(如果您希望使用本地的 https)

安装

通过 Composer

$ composer require jamosaur/vali
$ php artisan vali:install
$ ./vendor/bin/vali up

设置向导将询问您一些关于您的要求的问题。回答这些问题,配置将为您生成。

第一次运行 up 可能需要一些时间,因为需要下载 Docker 镜像,后续运行将会更快。

添加 bash 别名

虽然不是必需的,但强烈建议为 vali 添加一个 bash 别名。

添加别名后,您可以通过 vali 而不是 ./vendor/bin/vali 来调用 vali。

为此,请将以下内容添加到您的 shell 配置文件(~/.zshrc, ~/.bashrc)中

alias vali='./vendor/bin/vali'

使用 HTTPS

要使用本地的 https,我建议使用 mkcert 来生成您的证书。

在您的项目目录中运行以下命令

vali certificates

vali 将询问您要使用的域名。 它将自动为您创建一个通配符证书

输入 vali.test 将生成一个适用于 vali.test 以及 *.vali.test 的单个证书

或者,如果您想手动创建这些

$ mkdir certificates # We will store the certificates in this folder
# For a single domain (e.g. vali.test)
$ mkcert -key-file certificates/server.key -cert-file certificates/server.crt vali.test
# For a wildcard
$ mkcert -key-file certificates/server.key -cert-file certificates/server.crt vali.test \*.vali.test

用法

如果您计划使用本地的 https,最好先阅读上面的 使用 HTTPS 部分。

通过运行 vali:install artisan 命令开始。

php artisan vali:install

这将创建一个 docker-compose.yml 文件在您的项目根目录下。它还将创建一个位于您的配置文件夹中的 nginx-config.conf 文件。您可以在此处对您的 nginx 配置进行任何修改。

可用命令

help          Show this output
certificates  Create HTTPS certificates.
up            Start the containers
up -d         Start the containers in the background
down          Stop all of the running containers
build         Build all of the containers
php           Run a PHP command in the container
artisan       Run an artisan command. e.g. vali artisan test
composer      Run composer in the container
migrate       Migrate database
mfs           Refresh the database and seed
test          Run tests via artisan
tinker        Launch a tinker session in the container
shell         Launch a bash session in the container
rootshell     Launch a root bash session in the container

许可

MIT 许可证(MIT)。请参阅 许可文件 了解更多信息。