Reputation: 1071
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:
$PATH
.laravel new new-blog
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?
Upvotes: 23
Views: 148633
Reputation: 1
I faced the same issue, and the solution was straightforward.
For Windows operating system, if you are using a local development environment like XAMPP, all you need to do is locate the php.ini file (in my case, it was in C:\xampp\php
), open it, and remove the semicolon ;
from the following line:
You will find it like this
;extension=zip
Remove semicolon:
extension=zip
And it should work properly.
Upvotes: 0
Reputation: 819
This error can also be caused by not (manually) updating section "files" in composer.json
, i.e.:
"files": ["app/Some/Stucked/Refactored/Old/Location.php",
"app/Some/Good/Location.php"],
Then:
composer update
Upvotes: 0
Reputation: 41
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.
Upvotes: 0
Reputation: 31
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.
Upvotes: 3
Reputation: 4804
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
Upvotes: 3
Reputation: 1266
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
Upvotes: 28
Reputation: 682
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
Upvotes: 8
Reputation: 19
you don't have vendor folder in you project you need to re-install laravel & then try install it using
laravel new project
or composer create-project ---prefer-dist laravel/laravel blog
Upvotes: 1