简体   繁体   中英

php artisan: "failed to open stream: No such file or directory"

I just started to learn php/laravel by following some guides and tutorials, which led me to run a server using php artisan serve command.

The steps I took are as follows:

  1. install laravel using composer and adding it to $PATH .
  2. creating a project by using laravel new new-blog
  3. changing directory into the project foler and running php artisan serve command.

However, instead of the expected output of a php server with an address I get this error:

PHP Warning:  require(/home/sflash/Documents/php/laravel/new-blog/vendor/autoload.php): failed to open stream: No such file or directory in /home/sflash/Documents/php/laravel/new-blog/artisan on line 18
PHP Fatal error:  require(): Failed opening required '/home/sflash/Documents/php/laravel/new-blog/vendor/autoload.php' (include_path='.:/usr/share/php') in /home/sflash/Documents/php/laravel/new-blog/artisan on line 18

I am on a linux machine (debian buster). The structure of my project folder is like below:

app        composer.json  package.json  README.md  server.php  webpack.mix.js
artisan    config         phpunit.xml   resources  storage
bootstrap  database       public        routes     tests

As the error code above states, I don't have a file called vendor/autoload.php . How does this occur/how to fix this?

I just started to learn php/laravel by following some guides and tutorials, which led me to run a server using php artisan serve command.

The steps I took are as follows:

  1. install laravel using composer and adding it to $PATH .
  2. creating a project by using laravel new new-blog
  3. changing directory into the project foler and running php artisan serve command.

However, instead of the expected output of a php server with an address I get this error:

PHP Warning:  require(/home/sflash/Documents/php/laravel/new-blog/vendor/autoload.php): failed to open stream: No such file or directory in /home/sflash/Documents/php/laravel/new-blog/artisan on line 18
PHP Fatal error:  require(): Failed opening required '/home/sflash/Documents/php/laravel/new-blog/vendor/autoload.php' (include_path='.:/usr/share/php') in /home/sflash/Documents/php/laravel/new-blog/artisan on line 18

I am on a linux machine (debian buster). The structure of my project folder is like below:

app        composer.json  package.json  README.md  server.php  webpack.mix.js
artisan    config         phpunit.xml   resources  storage
bootstrap  database       public        routes     tests

As the error code above states, I don't have a file called vendor/autoload.php . How does this occur/how to fix this?

I just started to learn php/laravel by following some guides and tutorials, which led me to run a server using php artisan serve command.

The steps I took are as follows:

  1. install laravel using composer and adding it to $PATH .
  2. creating a project by using laravel new new-blog
  3. changing directory into the project foler and running php artisan serve command.

However, instead of the expected output of a php server with an address I get this error:

PHP Warning:  require(/home/sflash/Documents/php/laravel/new-blog/vendor/autoload.php): failed to open stream: No such file or directory in /home/sflash/Documents/php/laravel/new-blog/artisan on line 18
PHP Fatal error:  require(): Failed opening required '/home/sflash/Documents/php/laravel/new-blog/vendor/autoload.php' (include_path='.:/usr/share/php') in /home/sflash/Documents/php/laravel/new-blog/artisan on line 18

I am on a linux machine (debian buster). The structure of my project folder is like below:

app        composer.json  package.json  README.md  server.php  webpack.mix.js
artisan    config         phpunit.xml   resources  storage
bootstrap  database       public        routes     tests

As the error code above states, I don't have a file called vendor/autoload.php . How does this occur/how to fix this?

I just started to learn php/laravel by following some guides and tutorials, which led me to run a server using php artisan serve command.

The steps I took are as follows:

  1. install laravel using composer and adding it to $PATH .
  2. creating a project by using laravel new new-blog
  3. changing directory into the project foler and running php artisan serve command.

However, instead of the expected output of a php server with an address I get this error:

PHP Warning:  require(/home/sflash/Documents/php/laravel/new-blog/vendor/autoload.php): failed to open stream: No such file or directory in /home/sflash/Documents/php/laravel/new-blog/artisan on line 18
PHP Fatal error:  require(): Failed opening required '/home/sflash/Documents/php/laravel/new-blog/vendor/autoload.php' (include_path='.:/usr/share/php') in /home/sflash/Documents/php/laravel/new-blog/artisan on line 18

I am on a linux machine (debian buster). The structure of my project folder is like below:

app        composer.json  package.json  README.md  server.php  webpack.mix.js
artisan    config         phpunit.xml   resources  storage
bootstrap  database       public        routes     tests

As the error code above states, I don't have a file called vendor/autoload.php . How does this occur/how to fix this?

You have to add vendors directory first by running the install command for the composer:

composer install

After that update your composer packs:

composer update

At the end run your migration command

php artisan migrate
php artisan serve

All those solutions work if the dependencies have been downloaded.

I ran to a similar issue but with the Composer Update and/or composer i CLI solutions didn't work because there were files/dependencies missing or unable to be located.

I figured out that I required laravel in my project like so : composer global require laravel/installer and so the above solutions wouldn't be able to work. So I ran

composer help

and it led me to use the

composer u

and it downloaded all the required dependencies necessary.

then the

php artisan serve

command worked as expected.

Does this problem arise when you try to clone a project from GitHub? if true, then make sure the laravel installation on your device is correct by creating a local laravel project first. if the local project runs well, then you can proceed with cloning the project from the repository. after cloning project, duplicate file.envy.example and rename one of them to.envy then run composer update after that php artisan key:generate then you can try php artisan serve again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM