Laravel-应该采取什么步骤使Laravel应用程序准备好进入生产模式 [英] Laravel - What steps should one take to make a Laravel app ready for production mode
问题描述
方案是我在本地主机中开发了Laravel应用程序.一切正常.现在,我需要使其联机.我只是想弄清楚在使其联机之前应该采取哪些步骤(配置,安全性等).
我列出了一些步骤:
1)在 .env
文件中进行更改,以使环境使用 APP_ENV = production
指向生产模式.
2)避免直接在页面中显示错误,因为这会暴露应用程序的内在状况.改为启用错误日志记录.
3)使用缓存来获得更快的用户体验4)建立一个不错的404,但找不到页面
我还应采取什么措施将应用程序从开发模式转换为生产模式?
- 将更改应用于
.env
文件:-
APP_ENV =生产
-
APP_DEBUG = false
-
- 确保您正在优化Composer的类自动加载器映射( docs ):
-
composer dump-autoload --optimize
- 或安装时:
composer install --optimize-autoloader --no-dev
- 或在更新过程中:
composer update --optimize-autoloader
-
-
优化配置加载:
-
php artisan config:cache
-
-
优化路线负载
-
php artisan route:cache
-
- 编译应用程序的所有Blade模板:
-
php artisan view:cache
-
-
缓存框架引导文件:
-
php工匠优化
-
-
(可选)编译资产(文档):>
-
npm运行生产
-
-
(可选)生成Laravel Passport需要的加密密钥( docs ):
-
php工匠护照:钥匙
-
-
(可选),通过添加以下Cron条目来启动Laravel任务计划程序( docs ):
-
* * * * * cd/您的项目路径&&php artisan schedule:run>>/dev/null 2>& 1
-
-
(可选)安装,配置和启动Supervisor( docs ):
- (可选)创建从
public/storage
到storage/app/public
的符号链接( https://laravel.com/docs/master/deployment - Digital Ocean的教程:如何安装和配置Laravel
- Apply changes to
.env
file:APP_ENV=production
APP_DEBUG=false
- 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
Optimizing Configuration Loading:
php artisan config:cache
Optimizing Route Loading
php artisan route:cache
- Compile all of the application's Blade templates:
php artisan view:cache
Cache the framework bootstrap files:
php artisan optimize
(Optional) Compiling assets (docs):
npm run production
(Optional) Generate the encryption keys Laravel Passport needs (docs):
php artisan passport:keys
(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
(Optional) Install, config and start the Supervisor (docs):
- (Optional) Create a symbolic link from
public/storage
tostorage/app/public
(docs):php artisan storage:link
- Laravel deployment docs: https://laravel.com/docs/master/deployment
- Digital Ocean's tutorial: How to Install and Configure Laravel
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 ?
这篇关于Laravel-应该采取什么步骤使Laravel应用程序准备好进入生产模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!