Why my autoload.php of composer doesn't work? - php

I have a project, I use Composer and i import many thing by it... i require the autoload.php in my index (the root of project) and istead Slim, Mongo, Twig work very well. But when I call a class of Respect/Validation it doens't work; if I simply use Respect/Validation the error is:
Class 'Respect\Validation\Validator' not found in (path of file when i need it).
if I try to require also here the autoload.php the errors are:
**Warning**: require_once(vendor/autoload.php): failed to open stream: No such file or directory in (path of file when i need it)
**Fatal error**: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.;C:\xampp\php\PEAR') in (path of file when i need it)

Try using php composer dump-autoload. It may fix that problem.

If you are using a file (file.php) in a particular directory like this:
/app/controller/validation
and your vendor directory is in the base path of the project, you need to include the relative path to vendor directory:
../../../vendor/autoload.php

I did this.
i checked the file and permissions as always but everything looks ok. Then I open autoload.php and see ... oh! we have __DIR__ ofcourse.
I was doing this
require '../../vendor.autoload.php';
Changed to
require __DIR__.'../../vendor.autoload.php';
Not politically correct but got me by the frustrating waste of time for the moment.
ofcourse there are better alternatives to __DIR__ like using a BASE Path etc. But this worked for me.

I had the same issue with xampp. I installed composer and used:
composer create-project --stability=dev --prefer-dist yiisoft/yii2-app-basic D:\xampp\htdocs\newapp
My issue solved now.

I had the same problem and i solved it by using the last version of laravel, just try this code to create your project:
composer create-project laravel/laravel exampleProject --prefer-dist
this always uses the last version.

I solved simple re-run composer update from the project Root.
(my case was on Magento2, but the error and the path are the same)

In my case i simple forgot to change my working directory before running the command composer require cboden/ratchet in cmd this fixed it cd c:\path to project\ then composer require cboden/ratchet

Related

Failed Opening autoload.php in Laravel 5

I have recently installed Laravel via Composer but I keep get the following error:
Warning:
require(/home/leovoon/public_html/laravel-eee/bootstrap/../vendor/autoload.php):
failed to open stream: No such file or directory in
/home/leovoon/public_html/laravel-eee/bootstrap/autoload.php on line
17
Fatal error: require(): Failed opening required
'/home/leovoon/public_html/laravel-eee/bootstrap/../vendor/autoload.php'
(include_path='.:/opt/cpanel/ea-php71/root/usr/share/pear') in
/home/leovoon/public_html/laravel-eee/bootstrap/autoload.php on line
17
Am I missing something? Because I followed it step by step.
You got an error because you have missing vendor folder in your project, You need /vendor because all your packages are there, including all the classes Laravel uses. The vendor directory contains your Composer dependencies.
Your problem can be resolved after following this step. you can try it:
composer update --no-scripts
composer update
With this command, you will re-create the vendor folder in your project and after that your project will start working normally.
While Going Live This is my Project Structure
NOTE:WHILE DOING THIS YOU MAY ENCOUNTER SOME STYLE AND JAVASCRIPT REFERENCE ERROR
IF YOU ARE USNIG ASSET FUNCTION NO NEED TO WORRY
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
BUT IF NOT IF WILL OCCUR 404 IN SOME CASES
this is Just For Example
Step 1 : create a folder named as `ProjectFiles` in root of your application
Step 2: copy all the contents except and folder except `public` folder and paste inside `ProjectFiles` folder
Step3: now cut and paste all the contents inside the public folder in root of your application root
step4: open your index.php file and make the following changes
require __DIR__.'/../vendor/autoload.php';
to
require __DIR__.'/ProjectFiles/vendor/autoload.php';
AND
$app = require_once __DIR__.'/../bootstrap/app.php';
to
$app = require_once __DIR__.'/ProjectFiles/bootstrap/app.php';
and then upload your project to live cpanel server
here is my cpanel server directory structure
hope it helps if the answer is not clear please comment below if the error continues
I got this error after trying to start the dev server using php artisan serve
This is how I resolved it:
Run composer install
In case you get an error like "Your requirements could not be resolved to an installable set of packages", make sure you have the necessary extensions enabled in your php.ini config.
In my case I needed to enable extension=fileinfo
Run composer update. After this you should be able to start the server with no errors.
Run composer with --no-scripts
composer update --no-scripts
This shall fix the issue.
You must provide Read and write permissions to your project and generate a key in your .env file
Run the following commands inside your project dir and you would be good to go :
$ sudo chmod -R 777 /storage /public /bootstrap
$ composer install
$ php artisan key:generate
You must provide Read and write permissions to your project and generate a key in your .env file
You must provide Read and write permissions to your project and generate a key in your .env file

require(vendor/autoload.php): failed to open stream

I know that this issue has been posted many times, but for me it seems to be a different problem.
Indeed, this error
Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\site_web\send_mail.php on line 3
Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\site_web\send_mail.php on line 3
appears at the begining of my code from this line:
require 'vendor/autoload.php';
So, I guess there must be a /vendor/autoload.php file somewhere in my computer (I have installed composer and ran composer require phpmailer/phpmailer).
So, I looked for this file using: dir /s autoload.php in the Windows command line, and found one here: C:\Windows\SysWOW64\vendor\autoload.php,
but for me, syswow64 folder has nothing to see with autoload.php, I don't see what I am missing here.
What you're missing is running composer install, which will import your packages and create the vendor folder, along with the autoload script.
Make sure your relative path is correct. For example the example scripts in PHPMailer are in examples/, below the project root, so the correct relative path to load the composer autoloader from there would be ../vendor/autoload.php.
The autoload.php you found in C:\Windows\SysWOW64\vendor\autoload.php is probably a global composer installation – where you'll usually put things like phpcs, phpunit, phpmd etc.
composer update is not the same thing, and probably not what you want to use. If your code is tested with your current package versions then running update may cause breakages which may require further work and testing, so don't run update unless you have a specific reason to and understand exactly what it means. To clarify further – you should probably only ever run composer update locally, never on your server as it is reasonably likely to break apps in production.
I often see complaints that people can't use composer because they can't run it on their server (e.g. because it's shared and they have no shell access). In that case, you can still use composer: run it locally (an environment that has no such restrictions), and upload the local vendor folder it generates along with all your other PHP scripts.
Running composer update also performs a composer install, and if you do not currently have a vendor folder (normal if you have a fresh checkout of a project), then it will create one, and also overwrite any composer.lock file you already have, updating package versions tagged in it, and this is what is potentially dangerous.
Similarly, if you do not currently have a composer.lock file (e.g. if it was not committed to the project), then composer install also effectively performs a composer update. It's thus vital to understand the difference between the two as they are definitely not interchangeable.
It is also possible to update a single package by naming it, for example:
composer update ramsey/uuid
This will re-resolve the version specified in your composer.json and install it in your vendor folder, and update your composer.lock file to match. This is far less likely to cause problems than a general composer update if you just need a specific update to one package.
It is normal for libraries to not include a composer.lock file of their own; it's up to apps to fix versions, not the libraries they use. As a result, library developers are expected to maintain compatibility with a wider range of host environments than app developers need to. For example, a library might be compatible with Laravel 5, 6, 7, and 8, but an app using it might require Laravel 8 for other reasons.
Composer 2.0 removed any remaining inconsistencies between install and update results; if you're running composer 1.x you should definitely upgrade.
If you get the error also when you run
composer install
Just run this command first
composer dump-autoload
This command will clean up all compiled files and their paths.
#Bashir almost helped me but I needed:
composer update --no-scripts
Apparently this prevents any scripts from being included before executing artisan.
I found the answer here half-way down the page:
https://laracasts.com/discuss/channels/general-discussion/fatal-error-class-illuminatefoundationapplication-not-found-in-pathtoprojectbootstrapappphp-on-line-14?page=0
Proper autoload.php configuration:
A) Quick answer:
Your autoload.php path is wrong. ie. C:\Windows\SysWOW64\vendor\autoload.php
To date: you need to change it to: C:\Users\<Windows User Name>\vendor\autoload.php
B) Steps with example:
We will take facebook/php-graph-sdk as an example; change to Package Name as needed.
Install composer.exe
Open CMD Prompt. + R + type CMD
Run This command: composer require facebook/graph-sdk
Include path in your PHP page: require_once 'C:\Users\<Windows User Name>\vendor\autoload.php';
Define configuration Secrets and Access Token for your package...etc.
Happy codinig.
C) Further details:
Installing composer on windows will set this default path for your pacakges; you can find them there and include the autoloader path:
C:\Users\<Windows User Name>\vendor
For the same question you asked; the answer was this path for WAMP Server 64 BIT for Windows.
Then simply in your PHP Application change this:
require_once __DIR__ . '/vendor/autoload.php';
To:
require_once 'C:\Users\<Windows User Name>\vendor\autoload.php';
Find your windows username under C:\Users\
Before all this, as pointed before in B) , you need to run this command:
composer require <package name>
for facebook php SDK for example:
composer require facebook/graph-sdk
Thank you for asking this question; appreciated as it helped me fix similar issue and ended writing this simple tutorial.
First make sure you have installed the composer.
composer install
If you already have installed then update the composer.
composer update
If you have cloned your project from Github or got it from somewhere else, you will encounter this error. That's because you are missing the vendor folder and other files. The vendor folder contains packages which are dependent to your project. The package dependencies are stored in composer.json file and the folder was excluded while pushing to Github.
Fix this error by simply running:
composer install
Then you will get all the assets needed for your project.
First, review route inside index.php
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
in my case the route did not work, I had to review the directories.
For me
Just run this command first
composer dump-autoload
to add vendor folder.
then run this command
composer update --no-scripts
to update composer.
Create composer.json file with requisite library for ex:
{
"require": {
"mpdf/mpdf": "^6.1"
}
}
Execute the below command where composer.json exists:
composer install
In case of Drupal :
Use the web root folder of drupal to include autoload for ex:
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/vendor/autoload.php';
In case of other systems:
Use the root folder variable or location to include the autoload.php
I had this path in my machine:
C:/xampp5.0/htdocs/project-recordando-symfony/project-recordando-symfony
Then I ran composer install or/and composer update and it returned this error:
ErrorException ZipArchive::extractTo...
That error is because your path is too much long, I changed to:
C:/xampp5.0/htdocs/p-symfony/*
and worked!
run composer update. That's it
I was able to resolve by removing composer and reinstalling the proper way. Here is what I did:
sudo apt remove composer
sudo apt autoclean && sudo apt autoremove
Installed globally with the instructions from: https://getcomposer.org/doc/00-intro.md
Download from: https://getcomposer.org/installer
global install: mv composer.phar /usr/local/bin/composer
(Note: I had to move mine to mv composer.phar /usr/bin/composer)
I was then able to get composer install to work again. Found my answer at the bottom of this issue: https://github.com/composer/composer/issues/5510
In your project folder, the vendor folder is missing so you got this error:
Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in
When you download the project through git, the project is downloaded without the vendor folder
You need /vendor because all your packages are there, including all the classes Laravel uses. The vendor directory contains your Composer dependencies.
The solution is simple, Just run this command:
composer update --no-scripts
composer update
composer update --no-scripts It will Skips execution of scripts defined in composer.json file.
composer update It will update your depencencies as they are specified in composer.json file.
With this command, you will re-create the vendor folder in your project and after that your project will start working normally.
This error occurs because of missing some files and the main reason is "Composer"
First Run these commands in CMD
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Then
Create a New project
Example:
D:/Laravel_Projects/New_Project
laravel new New_Project
After that start the server using
php artisan serve
In my case, It was due to the non-fully installation of the project, because I didn't have enough space on my hard disk
There will be a directory called "vendor" that needs to be in your root directory if you have a cloned repository and trying to set up that time this type of error occurring.
".gitingore" file has written code to not include vendor directory on GIT so after cloning GIT your project facing the issue of missing vendor directory.
Once you add vendor directory your project will start working again.
Change the auto_prepend_file property on php.ini
; Automatically add files before PHP document.
;http://php.net/auto-prepend-file
auto_prepend_file =
In linux first add github Personal access tokens
Navigate to GitHub's Personal Access Tokens page.
Hit "Generate new token" button.
Type something meaningful "Note", select "repo" as scope and hit "Generate token" button.
Take a note of the token.
5 type in terminal with you new "personal access token"
export COMPOSER_AUTH='{"github-oauth":{"github.com":"AB8cd4cab23a9d5399934a7d7698d3fa74e9cfAB"}}'
Run in terminal composer install

Why I can't find vendor/autoload.php for Google Calendar API?

I am following all steps to run a PHP Google Calendar Api. I followed this link: https://developers.google.com/google-apps/calendar/quickstart/php . In step 4 it asks to run quickstart.php, but as after running the file, it displayed me this error :
Warning: require(vendor/autoload.php): failed to open stream: No such
file or directory in
C:\xampp\htdocs\Calendar\google-api-php-client-master\quickstart.php
on line 2
Fatal error: require(): Failed opening required 'vendor/autoload.php'
(include_path='.;C:\xampp\php\PEAR') in
C:\xampp\htdocs\Calendar\google-api-php-client-master\quickstart.php
on line 2
Here's a check-list for you to go down with Composer and vendor/autoload.php:
Does your composer.json file exist in the root of your project? (Note: This may be up a level from your document root for your web server.)
Does the vendor folder exist in the same folder as your composer.json?
Are you using the correct relative path to find your vendor/autoload.php file?
If composer.json isn't in your project root, move it there. It's where it belongs and things will continue to go wrong for you until it's there.
The vendor folder and its autoload.php file are both automatically created when you run php composer.phar install or php composer.phar update. If they're missing, you need to run php composer.phar install.
Once you've verified that vendor/autoload.php exists and is in the correct location, make sure that you have a good relative reference to that file with your require statement.
I solve this issue using the followed command:
composer dump-autoload -o
I would execute it inside of the application folder.
Example:
c:\<< your_app_folder >>\composer dump-autoload -o.
After that, you will see the "vendor" folder. The autoload.php file will inside.
For more information, access the link:
http://phpenthusiast.com/blog/how-to-autoload-with-composer
This fixed it for me
make sure you have composer installed then try the below command in your terminal
composer update

Failure to find autoload.php

I'm stuck on a very basic problem:
I'm trying to use Laravel, which I installed on my windows 7 with composer.
When I try to access my website locally with Wamp, I get the error:
Warning:
require(C:\wamp\www\sitedirectory\public\protected\bootstrap/../vendor/autoload.php):
failed to open stream: No such file or directory in
C:\wamp\www\sitedirectory\public\protected\bootstrap\autoload.php on
line 17
Everywhere I can read that all I have to do is run composer install or update.
The problem is that I did run both and nothing has to be updated.
The files are where they are needed so I dont understand what could be the problem.
Does anyone have an idea of what could be my problem?
Thank you in advance.
Composer is a tool for managing and installing dependencies.
There should exist a file named composer.phar in the directory C:\wamp\www\sitedirectory\public\protected\. There you should execute the command composer.phar install (on the command line).
Then, the directory vendor containing the autoload.php etc. should be generated.
If the composer.phar does not exist (but at least a file named composer.json), follow the steps explained here to download composer.

Don't found a class php imported with composer [duplicate]

I have a project, I use Composer and i import many thing by it... i require the autoload.php in my index (the root of project) and istead Slim, Mongo, Twig work very well. But when I call a class of Respect/Validation it doens't work; if I simply use Respect/Validation the error is:
Class 'Respect\Validation\Validator' not found in (path of file when i need it).
if I try to require also here the autoload.php the errors are:
**Warning**: require_once(vendor/autoload.php): failed to open stream: No such file or directory in (path of file when i need it)
**Fatal error**: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.;C:\xampp\php\PEAR') in (path of file when i need it)
Try using php composer dump-autoload. It may fix that problem.
If you are using a file (file.php) in a particular directory like this:
/app/controller/validation
and your vendor directory is in the base path of the project, you need to include the relative path to vendor directory:
../../../vendor/autoload.php
I did this.
i checked the file and permissions as always but everything looks ok. Then I open autoload.php and see ... oh! we have __DIR__ ofcourse.
I was doing this
require '../../vendor.autoload.php';
Changed to
require __DIR__.'../../vendor.autoload.php';
Not politically correct but got me by the frustrating waste of time for the moment.
ofcourse there are better alternatives to __DIR__ like using a BASE Path etc. But this worked for me.
I had the same issue with xampp. I installed composer and used:
composer create-project --stability=dev --prefer-dist yiisoft/yii2-app-basic D:\xampp\htdocs\newapp
My issue solved now.
I had the same problem and i solved it by using the last version of laravel, just try this code to create your project:
composer create-project laravel/laravel exampleProject --prefer-dist
this always uses the last version.
I solved simple re-run composer update from the project Root.
(my case was on Magento2, but the error and the path are the same)
In my case i simple forgot to change my working directory before running the command composer require cboden/ratchet in cmd this fixed it cd c:\path to project\ then composer require cboden/ratchet

Categories