Laravel Sail 作为生产设置

标签 laravel database docker redis laravel-sail

Laravel 不久前发布了 Sail,作为开发人员环境的快速启动。它有一些典型的容器,例如MySQL、Redis、Meilisearch。

通常,它应该反射(reflect)生产环境,以便在开发过程中我们处理尽可能接近生产的东西。 Sail 附带了所有这些,因此我们拥有完整的设置。

现在许多应用程序都是容器化的,并放入 Lambda 或其他无服务器解决方案中进行生产,但我想知道,Sail 是否会参与其中?对于数据库、搜索、邮件,我们有一个专门的服务,每个服务都完全在 Docker 容器之外,那么我们的 Docker-compose 将在哪里出现呢?

正如(最后的问题来了):对于一个成熟的应用程序,我们是否使用 Sail 的 docker-compose 的任何部分来启动生产环境?如果是,那么是哪一部分以及如何进行?

最佳答案

Sail 实际上只提供开发 Docker 实例和开发平台(即 VSCode)之间的 Artisan 链接。它应该与生产平台上的部署无关。我想理论上你可以使用你的开发 Docker 容器(它们是从 docker-compose 衍生出来的)并将其部署到生产环境中,但这不是我们会做的,我也不建议这样做。

这就是我们使用 PHP 和 MySQL 运行基于 Linux 的 Apache 的方法。 这里需要注意的是,我们不会在生产中运行 Docker 容器,因此如果您这样做,这个答案不适合。如果您希望将开发 Docker 容器迁移到完全是生产环境的生产容器,不同的答案。

1. Copy the entire project folder onto the production machine in the /var/www/html 
   as a subdirectory
2. In Apache, create a VirtualHost container name (this is important) which points the 
   DocumentRoot to the "public" directory of the folder created (even more important for security).
3. You will need the following directive for the public directory:

   <Directory "/var/www/html/foldername/public">
     AllowOverride All
     Options -Indexes +FollowSymLinks
     DirectoryIndex index.php
     Allow from All
   </Directory>

4. Modify the .env file appropriately for the production values as you mentioned 
   you have different component servers from the sail/Docker container.

我们创建了脚本,当我们进行更改时,我们只需将适当的目录复制到生产环境中即可。如果您只是修改 Blade 模板或页面文件,则不需要复制整个框架。

关于Laravel Sail 作为生产设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73610511/

相关文章:

mysql - Docker MySQL 8 如何设置 --secure-file-priv

docker - 在 Windows 主机上的 docker 容器中运行 cron

html - Blade,在传递给局部 View 的变量中使用 html 未被渲染

javascript - 拉维尔 5.8 : middleware ignored when calling route from javascript but not from browser

php - 在 null LARAVEL 上调用成员函数 update()

php - 将图像信息导入数据库时​​出现问题

广播 channel 的 Laravel 授权不起作用

node.js - 更新后无法识别 Webpack

database - CouchBase 最大数据库容量

node.js - Docker:从容器到其他容器的 http 请求停滞