heroku-buildpack-php: File "./composer.json" cannot be found in the current directory
I’m using this buildpack with dokku and it’s getting to the point of deploying and hitting the following error:
[RuntimeException]
File "./composer.json" cannot be found in the current directory
config [-g|--global] [-e|--editor] [-a|--auth] [--unset] [-l|--list] [-f|--file FILE] [--absolute] [--] [<setting-key>] [<setting-value>]...
realpath: '': No such file or directory
setuidgid: fatal: unable to run heroku-php-nginx: file does not exist
[RuntimeException]
File "./composer.json" cannot be found in the current directory
I’m totally scratching my head as to what’s going on as composer.json exists in the project. The error is pretty obtuse too. I can’t tell what directory it’s working in at that point.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 24 (8 by maintainers)
I dug in a bit, looks like we don’t change directories into
$HOMEuntil after we load the profile. That was changed here.We have test app deploys which didn’t catch this bug, though none of those include the
heroku/*-getting-startedapps (not that this would have caught the error.Interestingly, using the experimental CNB support works fine with the buildpack change - well, assuming that the latest php buildpack is included in the current heroku CNB builder. Looks like they
chdirbefore sourcing files. I guess that’s safe?I’m going to make a change to
gliderlabs/herokuishto move thecd $app_pathto after the call toprocfile-setup-homeand before the rest of the env is executed. Should tests pass, I’ll merge/release, and then re-test with Dokku to verify that fixes the issue.Thank you @dzuelke for spending time investigating, it is very much appreciated 😃 Feel free to continue to pull me in if you think this is a bug related to the Dokku build/run environment vs a buildpack issue.
But can confirm the update to herokuish 0.5.21 fixed the issue:
Thanks @josegonzalez and @dzuelke. I guess this can be closed now?
My test deploy of
heroku/php-getting-startedwith the updatedProcfileseems to have worked withgliderlabs/herokuish:v0.5.21. Folks seeing this error in Dokku with the latest PHP buildpack should upgrade theherokuishpackage (apt or yum will probably help).Okay sounds good, if I understand you right you’re changing Dokku to
cd /appbefore sourcing profile files now, is that right?That’s definitely the right way to do; there might be all sorts of things in a profile script (also a user’s own
.profileincluded in the app tree) that assumes the cwd is$HOME, just like it would be on a shell.Sure, but that’s actually unrelated (I’ve made a note though to change the
Procfilethere since it’s shorter withoutvendor/bin/).The buildpack has been appending (not prepending, otherwise you end up with fiascos like those Node.js
lsetc packages from a few years ago)vendor/bin/(or, more specifically,composer config bin-dir) to$PATHfor years; this is so that one can run e.g.phpunit, but alsoheroku-php-apache2, because they’re on the path.That ultimately results in more portable apps, because a change to the composer config (some apps/frameworks have their binaries just in
bin/for instance) will not cause the app to fail to start.But the trouble here is that with a recent change, Composer is now installed as a Composer package, and with that, the setup of
$PATHwas moved from a hardcoded location inbin/compileto the normal installer hook we have inside the package itself. But that hook can’t have hardcoded paths, it needs to evaluatecomposer config bin-dirat runtime and then figure out the absolute path from that, but for that to work, the cwd must be/app, because/appcontainscomposer.jsonwith (maybe) thebin-dirconfigentry.That’s where that error message comes from - the
$PATHsetup logic in a.profile.d/script invokescomposer, but it’s not run in/app, so there is nocomposer.json. That’s why it also happens on a simple run ofbash, since the profile scripts are also sourced then (as they should be).The
setuidgid: fatal: unable to run heroku-php-nginx: file does not existerror is just a symptom, not the cause, and @markuspoerschke’s workaround only happens to work because the$PATHexport isn’t otherwise necessary, and the explicitvendor/bin/…call executes fine.@markuspoerschke that’s not what we’re debating here. Of course that works, since by that time the cwd is
/app.This issue is about
vendor/bin/not being set on the path correctly because the expression that does it (by invokingcomposer config bin-dir) is failing.@simar0at and @archy-bold can you dig a bit further, and maybe raise this with the Dokku maintainers? I wonder why
/appisn’t the cwd during shell startup, and I also wonder at what point it finally doescd /appto start the app.What is inside
.profile.d/01-app-env.sh? Only secrets? Or also basics like$HOMEetc?