Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

laravel

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?

like image 804
Silver Flash Avatar asked Sep 12 '25 16:09

Silver Flash


2 Answers

You have done everything correctly except you forget to add the vendor folder into your project directory, just try

 composer i 

Inside the project directory from the terminal, will solve your error. And if you get any other error then remove the composer.lock file and then try again.

UPDATE:

Instead of deleting the composer.lock file when facing issues like PHP version mismatch or dependency version locked just use

composer update
like image 154
Mudit Gulgulia Avatar answered Sep 15 '25 07:09

Mudit Gulgulia


This is caused because you're missing your "Vendor" directory which is causing a missing dependency error. To fix this you need to run:

Composer update

In most cases, updating the Composer will regenerate the vendor folder and the autoload.php file.

Alternatively, you can regenerate the autoload.php file using the command,

composer dump-autoload

If the Composer is found corrupted, uninstall the existing one and reinstall it. To install Composer, run this command in the root project folder:

Composer install
like image 34
Bradley Kirkland Avatar answered Sep 15 '25 05:09

Bradley Kirkland