Search code examples
phplaravelherokucaching

Laravel problem with cache file when deploy to heroku


My application is using laravel 8. I deploy it from github to heroku and I want to run the command below:

php artisan optimize

But I don't know how to run the command in heroku and if the command creates cache files in my app then heroku will delete them after specific time because they are not permanently files deployed from github. Anyone know how to deal with this pls tell me what to do. Thank you!

P/s: i tried to do like the link below but it didn't create any cache file in my app. https://dev.to/autoidle/laravel-deployment-optimization-on-heroku-1hkc

[new update] Problem solved. Just follow the link above and my answer below.


Solution

  • [new update] You can follow the link below and do exactly the same but you need to fix the part of Procfile from composer warmup to composer run-script warmup. That will solve the problem in this thread. https://dev.to/autoidle/laravel-deployment-optimization-on-heroku-1hkc

    composer.json:

        "scripts": {
           ...
           "warmup": [
               "@php artisan config:cache",
               "@php artisan route:cache",
               "@php artisan view:cache"
        ]
    },
    

    Procfile:

    web: composer run-script warmup && heroku-php-apache2
    

    enter image description here