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)

Commits related to this issue

Most upvoted comments

I dug in a bit, looks like we don’t change directories into $HOME until 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-started apps (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 chdir before sourcing files. I guess that’s safe?

I’m going to make a change to gliderlabs/herokuish to move the cd $app_path to after the call to procfile-setup-home and 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:

sudo apt-get update && sudo apt-get install herokuish=0.5.21

Thanks @josegonzalez and @dzuelke. I guess this can be closed now?

My test deploy of heroku/php-getting-started with the updated Procfile seems to have worked with gliderlabs/herokuish:v0.5.21. Folks seeing this error in Dokku with the latest PHP buildpack should upgrade the herokuish package (apt or yum will probably help).

Okay sounds good, if I understand you right you’re changing Dokku to cd /app before 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 .profile included in the app tree) that assumes the cwd is $HOME, just like it would be on a shell.

Small note while I am looking at it: Looks like the official php-getting-started uses the vendor/bin/heroku-php-apache2 version in it’s Procfile.

Sure, but that’s actually unrelated (I’ve made a note though to change the Procfile there since it’s shorter without vendor/bin/).

The buildpack has been appending (not prepending, otherwise you end up with fiascos like those Node.js ls etc packages from a few years ago) vendor/bin/ (or, more specifically, composer config bin-dir) to $PATH for years; this is so that one can run e.g. phpunit, but also heroku-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 $PATH was moved from a hardcoded location in bin/compile to the normal installer hook we have inside the package itself. But that hook can’t have hardcoded paths, it needs to evaluate composer config bin-dir at runtime and then figure out the absolute path from that, but for that to work, the cwd must be /app, because /app contains composer.json with (maybe) the bin-dir config entry.

That’s where that error message comes from - the $PATH setup logic in a .profile.d/ script invokes composer, but it’s not run in /app, so there is no composer.json. That’s why it also happens on a simple run of bash, since the profile scripts are also sourced then (as they should be).

The setuidgid: fatal: unable to run heroku-php-nginx: file does not exist error is just a symptom, not the cause, and @markuspoerschke’s workaround only happens to work because the $PATH export isn’t otherwise necessary, and the explicit vendor/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 invoking composer 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 /app isn’t the cwd during shell startup, and I also wonder at what point it finally does cd /app to start the app.

What is inside .profile.d/01-app-env.sh? Only secrets? Or also basics like $HOME etc?