Laravel-应该采取什么步骤使Laravel应用程序准备好进入生产模式 [英] Laravel - What steps should one take to make a Laravel app ready for production mode

查看:79
本文介绍了Laravel-应该采取什么步骤使Laravel应用程序准备好进入生产模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方案是我在本地主机中开发了Laravel应用程序.一切正常.现在,我需要使其联机.我只是想弄清楚在使其联机之前应该采取哪些步骤(配置,安全性等).

我列出了一些步骤:

1)在 .env 文件中进行更改,以使环境使用 APP_ENV = production 指向生产模式.

2)避免直接在页面中显示错误,因为这会暴露应用程序的内在状况.改为启用错误日志记录.

3)使用缓存来获得更快的用户体验4)建立一个不错的404,但找不到页面

我还应采取什么措施将应用程序从开发模式转换为生产模式?

解决方案

  1. 将更改应用于 .env 文件:
    • APP_ENV =生产
    • APP_DEBUG = false
  2. 确保您正在优化Composer的类自动加载器映射( docs ):
    • composer dump-autoload --optimize
    • 或安装时: composer install --optimize-autoloader --no-dev
    • 或在更新过程中: composer update --optimize-autoloader
  3. 优化配置加载:

    • php artisan config:cache
  4. 优化路线负载

    • php artisan route:cache
  5. 编译应用程序的所有Blade模板:
    • php artisan view:cache
  6. 缓存框架引导文件:

    • php工匠优化
  7. (可选)编译资产(文档):

    • npm运行生产
  8. (可选)生成Laravel Passport需要的加密密钥( docs ):

    • php工匠护照:钥匙
  9. (可选),通过添加以下Cron条目来启动Laravel任务计划程序( docs ):

    • * * * * * cd/您的项目路径&&php artisan schedule:run>>/dev/null 2>& 1
  10. (可选)安装,配置和启动Supervisor( docs ):

  11. (可选)创建从 public/storage storage/app/public 的符号链接( https://laravel.com/docs/master/deployment
  12. Digital Ocean的教程:如何安装和配置Laravel
  13. The scenario is I have developed a Laravel app in my localhost. Everything works fine. Now I need to make it go online. I am just trying to figure out what steps (configuration , security etc.) should I take before I make it go online.

    I am listing a few steps:

    1) Change in .env file to make the environment point to production mode using APP_ENV=production.

    2) Avoide showing errors directly in pages as that would expose the innards of the app. Enable error logging instead.

    3) Use caching for faster user experience 4) building a nice 404, not found page

    What else should I undertake to turn the app from development mode into production mode ?

    解决方案

    1. Apply changes to .env file:
      • APP_ENV=production
      • APP_DEBUG=false
    2. Make sure that you are optimizing Composer's class autoloader map (docs):
      • composer dump-autoload --optimize
      • or along install: composer install --optimize-autoloader --no-dev
      • or during update: composer update --optimize-autoloader
    3. Optimizing Configuration Loading:

      • php artisan config:cache
    4. Optimizing Route Loading

      • php artisan route:cache
    5. Compile all of the application's Blade templates:
      • php artisan view:cache
    6. Cache the framework bootstrap files:

      • php artisan optimize
    7. (Optional) Compiling assets (docs):

      • npm run production
    8. (Optional) Generate the encryption keys Laravel Passport needs (docs):

      • php artisan passport:keys
    9. (Optional) Start Laravel task scheduler by adding the following Cron entry (docs):

      • * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
    10. (Optional) Install, config and start the Supervisor (docs):

    11. (Optional) Create a symbolic link from public/storage to storage/app/public (docs):
      • php artisan storage:link


    这篇关于Laravel-应该采取什么步骤使Laravel应用程序准备好进入生产模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆