Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 7 - what needs to be done to put site in production mode?

What are the steps that need to be done when putting a site from development to production?

I am aware of:

  • in my .env file set APP_ENV=production
  • in my .env file set APP_DEBUG=false
  • I know that the app.js file should be minified even tough i dont know yet what that means..

is there something else that needs to be done?

like image 581
sharkyenergy Avatar asked Apr 27 '20 07:04

sharkyenergy


1 Answers

There is a section about deploying a Laravel application to production in the docs.

To sum it up:

  1. composer install --optimize-autoloader --no-dev, note that if you still want the require-dev packages you can leave off the --no-dev option
  2. php artisan config:cache
  3. php artisan route:cache
  4. php artisan view:cache

You can read more about compiling assets here and about minification here.

Minification is the process of minimizing code and markup in your web pages and script files. It’s one of the main methods used to reduce load times and bandwidth usage on websites. Minification dramatically improves site speed and accessibility, directly translating into a better user experience. It’s also beneficial to users accessing your website through a limited data plan and who would like to save on their bandwidth usage while surfing the web.

You can minify your assets with Laravel Mix the following way:

Mix version 5

// Run all Mix tasks and minify output...
npm run prod

Mix version 6

// Run all Mix tasks and minify output...
npx mix --production

You can read more about the APP_ENV environment variable here:

The current application environment is determined via the APP_ENV variable from your .env file.

As far as I am aware this does not change much out of the box, but if you use additional third party packages or Laravel packages like for example Telescope, it determines how these packages function, for example if the APP_ENV value is set to local, Telescope will record all data and every user will have access to the Telescope routes.

You can see a example here and here.

like image 196
Remul Avatar answered Sep 29 '22 07:09

Remul