From a developer experience perspective:
- Checked out 8.1.x
- Made my DB
- Made my settings file
- Visited the site... 500 error in browser with no meaningful details
- Went to apache log, found:
PHP Fatal error: require(): Failed opening required '/var/www/drupal8/vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/drupal8/autoload.php on line 14
Didn't really understand what I was supposed to do, thankfully I'm at the Midcamp sprint and was told I need to run composer install to get the external deps.
Comment | File | Size | Author |
---|---|---|---|
#59 | 2691003-59.patch | 693 bytes | Medha Kumari |
| |||
#54 | reroll_diff_42-54.txt | 875 bytes | pooja saraah |
#54 | 2691003-54.patch | 687 bytes | pooja saraah |
#42 | interdiff-37-42.txt | 1.8 KB | mpdonadio |
#42 | 2691003-42.patch | 685 bytes | mpdonadio |
Comments
Comment #2
wesruv CreditAttribution: wesruv at Lullabot commentedThink the error could be something like:
I'm not cool enough to know if you can send a separate message to the server log, but explicitly telling the dev to run composer install would be helpful, but not sure that should be told to a user seeing the error in browser.
Comment #3
mpdonadioSpitballing here.
Comment #4
mpdonadioAnother spitball that doesn't add a variable to the global scope.
Comment #5
Crell CreditAttribution: Crell as a volunteer commentedNot sure if this is the right way to approach it, but the error message (wherever it is) should include a link to the composer documentation for those who go "Composer? What does Mozart have to do with this?"
Comment #6
geerlingguy CreditAttribution: geerlingguy as a volunteer and at Acquia commentedAgreed... Or a link to a Drupal.org doc page on the setup, so we could make it more Drupal-specific.
Comment #7
dawehnerCould we not do a include_once and check the return value
Ideally we should point onto drupal.org explaining people to either run composer install or use the packages provided by Drupal.
Comment #8
Mile23autoload.php
is the source of the autoloader object. Its return value is important.Also, we want it to explode if it's present but malformed in some way.
The only way to do this is to do a
file_exists()
on every page load. However, the autoloader can be moved, and in fact *must* be moved for sane deployment as with https://github.com/drupal-composer/drupal-project , so thefile_exists()
will be checking the wrong place in many circumstances.Big -1 on this issue. The user will see that there is a problem, will find out that we have a lot of documentation on the issue, and then will learn how to use Composer.
We should instead provide a how-to-install text file at the root level of the repo, which currently does not exist.
Comment #9
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer and commentedMy initial reaction is to agree with Mile23, seems like something that could be handled with just documentation. You're going to have to follow an installation guide anyway for some of the other requirements.
Comment #10
andypost#8 makes sense but errors should be user friendly
Comment #11
dawehnerI agree with #10, this issue is all about providing a helpful error message.
Comment #12
catchPatch #4 looks a lot better than the file_exists(), for me I'd just add an error message to that and remove the @ error suppression - it's fine to show the PHP warning in this situation.
If we don't like the $autoloader return check, we could also do a class_exists() on DrupalKernel which is the next thing that fails.
Comment #13
hussainwebI'm trying something slightly different. Based on @catch's suggestion in #12, I am checking for the class itself. I am just changing the require to include in autoload.php.
I agree with @Mile23's concerns but I am not sure how they apply here. We are modifying the autoload.php which is supposed to be edited by the user if they place the vendor directory elsewhere. The drupal-composer project (with drupal-scaffold) edits this file with the actual relative vendor path. Now, if the file has been edited in such a way, it means either that the user knows about composer and would recognize the error or the user has already run
composer install
, in which case we don't need to worry anymore.On the other hand, if the user doesn't know about composer and sees the error, they would just have to follow the documentation. It is unlikely that they would be affected by moving the vendor elsewhere. If they want to move it, they have to again edit the autoload.php which is already a requirement.
Please let me know if I am missing something else.
Comment #14
hussainwebIn case it's not clear. I am changing
require
toinclude
to avoid a fatal when the file doesn't exist. This approach also handles problems when the file is present but not valid in some way (as raised in #8). I am also aware that there might be a problem which might allow DrupalKernel to load but not other classes, but that seems like an extreme edge case and not the problem described in the issue (which is that the user has forgotten to runcomposer install
).Comment #15
dawehnerYeah I would argue that we should not mention that DrupalKernel wasn't found ...
Comment #16
Mile23If you look at drupal/core composer.json autoload section you'll see that
\Drupal
is the most performant class lookup.Also +1 on saying what the error is rather than what we looked up.
Comment #17
Mile23Comment #18
anoopjohn CreditAttribution: anoopjohn at Zyxware Technologies commentedPlease find attached a patch with the suggested changes. I have revised the error message to
I have also changed the class being tested to
\Drupal
I have prepared this against 8.2.x. Hope that is the right way to do this.
Comment #19
RobLoach1. Checking the return object of
include
is a bit cleaner (it's the Composer loader object)2. Ignoring the warning from include will save a PHP fatal error from happening
Comment #20
Mile23If not having installed with Composer were the only possible error with this, then
@include
might be OK, but it's not.If we were normalizing on PHP 7, we could do this easily with a try/catch on
\Error
, but we can't.That leaves poking around in
error_get_last()
and figuring out what to tell the user.Comment #21
andypost.' . PHP_EOL .
+ 'Refer to the the Drupal installationg guide for instructions on installing with Composer.';
This not clear that problem in autoloader
Comment #23
wmostrey CreditAttribution: wmostrey commentedI ran into the same problem, and the patch in #19 seems like a clean way to solve this.
Mile23: what other causes except for Composer could this have?
Comment #24
Mile23RE:
$autoloader = @include __DIR__ . '/vendor/autoload.php';
If there's no
vendor/autoload.php
file, or a symlink can't be reached, or apache doesn't have read access to it, or whatever else, then I want to learn that from the error message.So swallowing the error with
@include
is bad. We should test what it does, not whether it's there.Much prefer #18, which looks for
\Drupal
and then complains if it doesn't work.Comment #25
wmostrey CreditAttribution: wmostrey commentedAgreed. So let's mark this for review again?
Comment #26
amgoncalves CreditAttribution: amgoncalves at Last Call Media commented#18 helped me solve this issue when I ran into it earlier today.
Comment #27
amgoncalves CreditAttribution: amgoncalves at Last Call Media commentedComment #28
Mac_Weber CreditAttribution: Mac_Weber as a volunteer commentedPatch #18 does not work with Drush.
Patch #19 still needs work as pointed by @Mile23 at #24
Comment #29
icicleking CreditAttribution: icicleking at Last Call Media commented@Mac_Weber, updating how Drush throws this error seems out of scope of this bug. I *think* the goal here is to provide a meaningful error to a site-builder/developer who installs the site, but hasn't run `composer install`. Currently when I run a drush command on a site without running `composer install`, I get the following error:
In other words, I would argue it's up to Drush to provide a more meaningful error, if it's required. Therefore, patch #18 from anoopjohn is sufficient.
Comment #31
Mac_Weber CreditAttribution: Mac_Weber as a volunteer commented@icicleking, if the intention is to give meaningful information to developers then displaying that message on Drush makes sense. IMHO, most developers do not install using the GUI.
I'm adding a patch that merges both solutions and I changed the error message to something that gives the necessary hints to developers for how to solve the issue with the
vendor
folder and the dependency files.In addition, I did many tests. One of them was deleting the file
/vendor/autoload.php
, but keeping all other files. In this test the installation worked on the GUI with patch #18. Then, I think this is also one more reason for merging both patches.I added
'<br>' . PHP_EOL
because one works on browsers and the other only works at command line, giving a better output ;)Comment #32
wmostrey CreditAttribution: wmostrey commentedTested it thoroughly and works as expected. One remark: we should probably use
<br/>
instead of<br>
.Comment #33
wmostrey CreditAttribution: wmostrey commentedSorry, wrong patch. Here's the right one.
Comment #34
xjmNote that issues like this should be targeted against 8.4.x, but can be considered for backport once they are committed to that branch. See the updated alpha release policy. Thanks!
Comment #35
wmostrey CreditAttribution: wmostrey commentedPatch against 8.4.x-dev.
Comment #36
ptmkenny CreditAttribution: ptmkenny commentedSome minor English fixes to the patch in #35:
Revisions
at the vendor folder -> in the vendor folder
", too" in the second line is redundant (because of also), so I removed it.
installationg -> installation
Comment #37
yogeshmpawarChanges made as per comment #36.
Comment #40
borisson_Setting to RTBC. The error message is suffiently clear.
Comment #41
alexpottWhy not change this to
if (!$autoloader || !class_exists('\Drupal)) {
and remove the changes from index.php.I'm not sure about the text
Dependencies error!
- I think the exclamation mark is unnecessary. Perhaps the entire test might be better it is more to the point. Something like:Failed to set up the autoloader. This can occur because composer install has not been run. Refer to https://www.drupal.org/docs/8/install/step-2-install-dependencies-with-composer for more information.
I don't think the message should contain HTML or even set headers as this can cause problems when this occurs from the the CLI. However I think we should do
exit(1);
.Finally the link in the message in the patch should be https://www.drupal.org/docs/8/install/step-2-install-dependencies-with-c... whatever text we go for. It's good to see we're not really recommending starting from a git checkout on the installation instructions anymore.
Comment #42
mpdonadioHow about this? Tested manually with both apache and drush, and seems to work fine.
Comment #44
joachim CreditAttribution: joachim as a volunteer commentedLGTM.
Comment #53
volegerThe link has to be https://www.drupal.org/docs/installing-drupal/step-2-install-dependencie... .
Comment #54
pooja saraah CreditAttribution: pooja saraah at Srijan | A Material+ Company for Drupal India Association commentedAttached reroll patch against 9.5.x
Addressed the comment #53 and the link has been changed.
Comment #55
joachim CreditAttribution: joachim as a volunteer commentedGreat, thanks!
Comment #56
alexpottThanks for working on this issue. Helpful errors are helpful!
Given
I think we can revisiting the solution.
The point of the issue is to emit a helpful message when composer has not run. I don't think that suppressing the warning about the file not existing is necessary. So we can now do:
Comment #57
alexpottAlso one thing that is fun is that this is way less of a problem now that the recommended way to start a project is using composer as detailed on https://www.drupal.org/docs/develop/using-composer/starting-a-site-using...
So the only people who face this issue are people working on core development using the git checkout. This realisation indicates some things:
I think given the existence of the composer templates and the fact the tarball includes everything you need we should close this issue as outdated. Note that when this issue was open the composer templates did not exist.
Comment #58
alexpottDiscussed with @catch and we both agree that this has become outdated due to the existence of the composer project templates and the fact that they are the recommended way of installing Drupal. Unless there is a valid point to do not close this issue I will mark it outdated on the 4th July.
Comment #59
Medha KumariReroll the patch #39 with Drupal 10.0.x
Comment #60
borisson_As mentioned in #58, this is now outdated.