25

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 ?

Istiaque Ahmed
  • 6,072
  • 24
  • 75
  • 141

3 Answers3

78
  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. Discover and cache the application's events and listeners:

    • php artisan event:cache
  5. Optimizing Route registration:

    • php artisan route:cache
  6. Compile all of the application's Blade templates:

    • php artisan view:cache
  7. Cache the framework bootstrap files:

    • php artisan optimize
  8. (Optional) Asset Bundling:

    • Using Vite Laravel Plugin (docs): npm run build
    • Using Laravel Mix (docs): npm run production
  9. (Optional) Generate the encryption keys Laravel Passport needs (docs):

    • php artisan passport:keys
  10. (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
  11. (Optional) Install, config and start the Supervisor (docs):

  12. (Optional) Create a symbolic link from public/storage to storage/app/public (docs):

    • php artisan storage:link

Hafez Divandari
  • 8,381
  • 4
  • 46
  • 63
  • 3
    `php artisan optimize` hasn't been needed since Laravel 5.5 – Amir Asyraf Jan 09 '20 at 13:26
  • 1
    @AmirAsyraf currently optimize is as same as calling `config:cache` and `route:cache`, however I preferred to mention it due to probable behavior changes in the future. – Hafez Divandari Jan 09 '20 at 13:32
  • @HafezDivandari Is there a reason that compiling assets with `npm run` is optional? Isn't it required? – Hashim Aziz Mar 24 '22 at 20:42
  • 1
    @HashimAziz the app may don't have any front-end assets to compile, on the other hand there is no need to re-compile assets on the deployment if you haven't injected any [env variables](https://laravel.com/docs/9.x/mix#environment-variables) – Hafez Divandari Apr 05 '22 at 19:17
  • @Hafez thanks. Really useful. I had to use ```npm run build``` instead of ```npm run production``` – Robert Yeomans Jan 21 '23 at 16:18
4

There are some steps you can check

  1. Install LEMP or LAMP stack.
  2. You can check/add PHP and Dependencies for Laravel
  3. Test Your Site’s Functionality
  4. Optimize Image Size
  5. Google Analytics & SEO addition
  6. Check w3 validation
  7. Page speed optimization
1

configuration

  • set app_debug to false
  • make sure you are setting proper folder permissions

Security

  • use ssl certificate -> you can do configuration with nginx or apache for the same
  • redirect all requests to https after setting up ssl
  • set very strong database password
  • if your app has api's then use api throttling
Chirag Chaudhari
  • 1,617
  • 3
  • 14
  • 20