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

2

5

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?

Geocentric answered 27/4, 2020 at 7:51 Comment(1)
php artisan optimizeDieldrin
P
10

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.

Pneumonoultramicroscopicsilicovolcanoconiosis answered 27/4, 2020 at 8:2 Comment(8)
thank you very much.. just a little question: is this additional to the change of the .env file or is it done automatically with one of these steps?Geocentric
You will need to change your .env as well.Pneumonoultramicroscopicsilicovolcanoconiosis
thank you! what does the APP_ENV actually do? debug is clear, but app_ENV id ont understand.. also tried to read it up but still dont understandGeocentric
@Geocentric I added an explanation about APP_ENV to the answer, hope it helps.Pneumonoultramicroscopicsilicovolcanoconiosis
thank you very much! I've followed your steps and now the site is giving 500 errror: Class 'Facade\Ignition\IgnitionServiceProvider' not foundGeocentric
Do you see this error in your browser or in the logs? Did you set your APP_DEBUG to false?Pneumonoultramicroscopicsilicovolcanoconiosis
The problem is that ignition is not installed after running composer install --optimize-autoloader --no-dev since it is listed in the require-dev packages, the reason being that you shouldn't turn on the debug mode in a production environment. If you still want the require-dev packages you can run composer install --optimize-autoloader instead. Additionally you should test if the deployment works in your local environment on your computer first instead on the server directly.Pneumonoultramicroscopicsilicovolcanoconiosis
thank youv ery much Remul, its working now! :) please add it to the answer as alternative to the first step..Geocentric
C
1

There are many things to do to make your site production ready.

  • Caching (Queries, Views ETC)
  • Use of webpack (To bundle assets & minify them)
  • Use cdn for the asset bundles (So they load faster which will increase your website loading speed)
  • Deploying website on cloud for better resources.
  • ETC

So you can't just simply make a website production ready by updating your .env file.

You might need to read some articles on google about laravel production ready website

Cyanide answered 27/4, 2020 at 7:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.