0

I want to deploy my project on heroku. I installed everything and tried running database seed command which gives me error that Faker factory isnt included. Checked my gitignore file saw that vendor folder is ignored.

Is it good practise to push vendor folder? Or how else could I solve this problem?

zerociudo
  • 357
  • 8
  • 25
  • Not a good idea to push vendor files. In NodeJS projects you usually have a heroku script that builds the project and deploys it. **I'm not very familiar with Laravel** , but this might be the same thing you should do. – Baruch Sep 16 '17 at 10:31
  • It is part of gitignore that's why it does not push. You don't need to push vendor folder. After you pull your repo, `composer update` will have you all your vendors files back. – Michel Sep 16 '17 at 10:32
  • I am not sure I ran following commands: inline `git add . ; git commit ; git push heroku master ; heroku run composer update --dev ;heroku run php artisan db:seed ` and it still gives me same error. – zerociudo Sep 16 '17 at 10:45
  • it's not update it's `composer install`. pls try the solution i provided below – limco Sep 16 '17 at 10:49
  • 1
    you also have to migrate `heroku run php artisan migrate` before you seed `heroku run php artisan db:seed`. – limco Sep 16 '17 at 10:50
  • yes you are correct tried running your solution i think it will work just got some sql errors now. `Connection refused Is the server running on host "127.0.0.1" and accepting`. I probably mised a step or so. – zerociudo Sep 16 '17 at 10:56
  • @zerociudo for that you need to look at your .env file and change the `DB_HOST=127.0.0.1` to the heroku db host – limco Sep 16 '17 at 10:58
  • @zerociudo and don't forget about `DB_DATABASE`, `DB_USERNAME` and `DB_PASSWORD` – limco Sep 16 '17 at 10:59
  • @limco thats the weird part I changed those before and its correct, do I need to change it anywhere else besides .env file? – zerociudo Sep 16 '17 at 11:03
  • @limco changed it in database.php (forgot that, stupid me). I think it fixed that, but got different error sadly. Do I need to change redist host, because its default in my project? – zerociudo Sep 16 '17 at 11:15
  • It was a random thought to try that but no it doesn't make sense to. – limco Sep 16 '17 at 11:17
  • Managed to fix it another typo, thanks for your help. – zerociudo Sep 16 '17 at 11:18

2 Answers2

2

Running composer install on Heroku via heroku run isn't a good idea. Heroku's filesystem is ephemeral. Anything you write to it (for example, libraries installed to vendor/) will be lost the next time your dyno restarts. This happens frequently.

The correct solution is to make sure that your composer.json and composer.lock are accurate, up-to-date, and committed to your repository. If you need the faker on Heroku it should be required, not require-deved. Heroku will run composer install automatically as part of the deploy process.

Aside from the ephemeral filesystem issue, this also means that vendor/ will become part of the compiled application slug, ensuring that vendor files are available on every dyno if you ever scale beyond a single one.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
0

open heroku command line

do heroku run composer install

then heroku run php artisan migrate to setup the tables

then heroku run php artisan db:seed to seed the db

if you get any database errors or when migrating, try doing php artisan migrate:reset then php artisan migrate

Also, check your composer.json file and make sure you have "fzaninotto/faker" under require. If you only have it under require-dev then it's not being installed when you deploy on production unless you used the dev flag heroku run composer install --dev

Refer to Deployment on Laravel Forge throwing faker not found Exception

And to also answer your question, it's generally better to ignore the vendor folder and use composer to install dependencies, hence gitignore.

limco
  • 1,310
  • 1
  • 15
  • 24