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?
php artisan optimize creates a compiled file of commonly used classes in other to reduce the amount of files that must be included on each request. After running the command, all commonly used classes are compiled and then saved to this file directory: bootstrap/cache/compiled.
Optimize Composer Laravel uses a separate tool called Composer to manage different dependencies. When you initially install Composer, it loads dev dependencies into your system by default. These dependencies are useful for developing a website.
[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
As of Laravel 5.5, php artisan optimize
is not longer required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With