Warning: require(…): failed to open stream: No such file or directory in

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

just moved over my laravel site to my live server and straight away faced with this error.

The complete error is:

Warning: require(/var/sites/b/beta.buildsanctuary.com/public_html/local/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /var/sites/b/beta.buildsanctuary.com/public_html/local/bootstrap/autoload.php on line 17  Fatal error: require(): Failed opening required '/var/sites/b/beta.buildsanctuary.com/public_html/local/bootstrap/../vendor/autoload.php' (include_path='.:/usr/local/lib/php') in /var/sites/b/beta.buildsanctuary.com/public_html/local/bootstrap/autoload.php on line 17 

The line 17 is:

require DIR.'/../vendor/autoload.php';

Folder structure is:

beta.buildsanctuary.com   -- public_html   -- subdomains     -- beta       -- local         -- bootstrap         -- vendor 

Any help where this is going wrong? And how to fix? Pulling my hair out trying all sorts of paths.

Thanks, Craig.

回答1:

As you can see from the error, PHP is looking for

public_html/local/bootstrap/../vendor/autoload.php` 

which is

public_html/local/vendor/autoload.php 

That folder does not exist. I think the folder structure you posted is wrong.

Anyway, try this:

require('../vendor/autoload.php'); 


回答2:

I've had the same problem and it was that Composer was not installed yet in the server, so the directories structure it creates on your project does not exist neither.

First you have to install composer on your server, follow the instructions for your system given at the composer project webpage, https://getcomposer.org/.

Next you have to go in a terminal or cmd to the base folder of your project.

There you can use the commandline composer init, wich will guide you to create your composer.json file into your project.

Once you have created your composer.json file, you have to execute the commandline composer install.

This commandline will create all the dependencies you have written on your composer.json, and also will create the folder structure so the code you require would find the proper path.

At last, you have to reference the redirection to the folder vendor depending on the current folder structure location of your php file.

If you look for information, http://www.phptherightway.com/ was really helpfull.



回答3:

I strongly believe that a corrupted cache was the cause, I cannot be 100% sure but it seem that it is likely the culprit.

So, if anyone comes across a similar problem, I would suggest the following steps:

  1. Delete the vendor folder
  2. Delete composer.lock
  3. Run the command composer clearcache (or clear-cache)
  4. Run composer install

I hope this can help somebody.



回答4:

Just run the following command, it will automatically install necessary dependencies:

composer install



回答5:

I had the same problem when I have had migrated a drupal website to new server... To solve the problem I just used the composer command:

  1. First cd into website directory, EX: cd /var/www/your_website

  2. Run composer to install drupal 8 dependencies that it's need in the website directory;

composer install

If you use the sudo command, make sure the .../vendor directory has the right permission to be accessed by the user who in the /var/wwwdirectory;

sudo composer install

This basically will solve the .../public_html/autoload.php on line 14 issue!



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!