Rob
Rob

Reputation: 70

Composer.json vendor folder on Heroku

I am migrating from shared web hosting to Heroku and can't figure out how to user Composer properly.

I have my app pointing to public_html folder, with the composer.json file in the root folder above this. This would generate a vendor folder in the root folder, which (for reasons I don't understand) I was unable to access when I tried including the autoload.php file in my code (e.g. require_once('../vendor/autoload.php')).

My solution to this was to move composer.json into public_html, but that caused no end of problems with Heroku not finding it, so I moved it back. I then changed the vendor directory in composer.json to point to public_html/vendor.

This had the desired effect, except now my app won't run because it can't find PHP, presumably something to do with the new location of vendor.

Is there a way to either:

  1. Configure composer.json to have Heroku put everything except PHP in public_html/vendor, and put PHP into a root vendor directory, or
  2. Access files above public_html from within my code to allow me to include autoload.php?

Upvotes: 1

Views: 1139

Answers (1)

Rob
Rob

Reputation: 70

OK, it turns out it was a relatively simple fix that I just figured out myself. I'll post it here in case anybody else happens to make the same mistake.

If you change vendor-dir in composer.json, you also need to change the Procfile from

web: vendor/bin/heroku-php-apache2 public_html/

to

web: public_html/vendor/bin/heroku-php-apache2 public_html/

Upvotes: 1

Related Questions