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.
My Answer:
I'm glad to hear that you were able to solve the problem. Just to provide some additional information for others who may encounter a similar issue, here are some steps you can take to run the `php artisan optimize` command on Heroku:
1. Add the `heroku/php` buildpack to your Heroku app by running the following command in your terminal:
heroku buildpacks:add heroku/php
2. Create a `Procfile` in the root directory of your Laravel project with the following content:
web: vendor/bin/heroku-php-apache2 public/
3. Add the following lines to your `composer.json` file in the `scripts` section:
"post-install-cmd": [
"@php artisan optimize"
],
"post-update-cmd": [
"@php artisan optimize"
]
4. Commit your changes and push them to your Heroku app.
By following these steps, the `php artisan optimize` command will be run automatically after each deployment to Heroku, ensuring that your cache files are generated and not deleted by Heroku's ephemeral filesystem.
Rate this post
4 of 5 based on 7450 votesComments