phplaraveloptimizationlaravel-5.1laravel-artisan

Laravel artisan optimize Best Practices


I'm trying to fully understand the Laravel (5.1) artisan optimize command and best practices, but the documentation seems lacking. I don't have Composer installed on the production server so, specifically, I want to know what files are modified or created when running artisan optimize --force on development that must get pushed to production. The goal being not to blow up the app in production! After running the command, I see the following files have been modified:

\bootstrap\cache\compiled.php
\vendor\composer\ - the entire directory
\vendor\autoload.php

Am I overthinking this, or do I just push these files to production and I'm good to go? Also, what is the best practice regarding when to run artisan optimize? Each time a new model is created? What about controllers, routes and helper classes?

Lastly, I see the \bootstrap\cache\compiled.php file is a whopping 548KB and almost 17K lines! Is that really considered optimal?


Solution

  • [edit - As @crishoj says, as of Laravel 5.5, php artisan optimize is no longer needed]

    Normal Laravel practice is to have composer installed on your production server.

    These are the steps Envoyer (made by Laravel's creator) takes to deploy an app on production -- I've annotated them below:

    # Install application dependencies, such as the Laravel framework itself.
    #
    # If you run composer update in development and commit the `composer.lock`
    # file to your repository, then `composer install` will install the exact
    # same versions in production.
    composer install --no-interaction
    
    # Clear the old boostrap/cache/compiled.php
    php artisan clear-compiled
    
    # Recreate boostrap/cache/compiled.php
    php artisan optimize
    
    # Migrate any database changes
    php artisan migrate