vendor/autoload.php: failed to open stream - php

I worked with a project using composer.But when i run the index file,system shows the following error,
Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in D:\xampp\htdocs\instagram_php\index.php on line 5
Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.;D:\xampp\php\PEAR') in D:\xampp\htdocs\instagram_php\index.php on line 5
I have installed composer from https://getcomposer.org/.
What am doing wrong?

You are using require_oncewith a relative path. It is possible but there are so many things that can go wrong that I usually avoid it.
Where is the vendorfolder relative to index.php? I recommend using an absolute path. You can use the magic constants to determine it:
require_once(__DIR__ . '/vendor/autoload.php');
NOTE: you can use /.. to go up the directory tree.
NOTE2: __DIR__ requires php 5.3 or higher. You can use dirname(__FILE__) for older versions.

Make sure vendor folder is there if not please Run following command:-
composer install

Related

Composer is not functioning?

I used composer install in the folder C:\xampp\htdocs\PhpstormProjects, exactly where my website files are located. Now, when I want to view the local version of my files at http://kabel.local.dev:8080, I'm getting these errors:
Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\PhpstormProjects\www\index.php on line 14
Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\PhpstormProjects\www\index.php on line 14
I am probably using the wrong path but I'm not sure which path I should use? I tried C:\xampp\htdocs\PhpstormProjects\vendor but my cmd says that doesn't contain composer.json, the cmd tells me
No composer.json in current directory, do you want to use the one at C:\xampp\htdocs\PhpstormProjects? [Y,n]?
Is your vendor folder in C:\xampp\htdocs\PhpstormProjects\ ?
If yes, you have to execute composer update in your C:\xampp\htdocs\PhpstormProjects\www\ folder.
By default, you have to execute composer commands at the same location where your index.php is located.
OR you can change in your index.php the line
require_once('vendor/autoload.php');
to
require_once('../vendor/autoload.php');
In your index.php file, try update the line 14 of
require_once('vendor/autoload.php');
to
require_once('vendor'.DIRECTORY_SEPARATOR.'autoload.php');
If this not work, please, send for us an picture for the folder structure or an snippet of your index.php

Require_once(Net/URL2.php): failed to open stream: no such file or directory

I installed the pear/http_request2 version 2.2.1 using Composer in my project but when I am trying to make my first request I am getting this Warning and Fatal error:
Warning: require_once(Net/URL2.php): failed to open stream: No such
file or directory in
/Applications/XAMPP/xamppfiles/htdocs/jet/vendor/pear/http_request2/HTTP/Request2.php
on line 24
Fatal error: require_once(): Failed opening required 'Net/URL2.php'
(include_path='/Applications/XAMPP/xamppfiles/htdocs/jet/vendor/pear/pear_exception:.:/Applications/XAMPP/xamppfiles/lib/php')
in
/Applications/XAMPP/xamppfiles/htdocs/jet/vendor/pear/http_request2/HTTP/Request2.php
on line 24
I appreciate any help on how to fix it, thanks in advance.
David.
This should work:
composer require pear/http_request2:2.2.1
By default pear/net_url2 should be installed which has the required URL2.php file (./vendor/pear/net_url2/Net/URL2.php).
Then make sure you're including vendor/autoload.php file in your scripts to load automatically the include paths (see: vendor/composer/include_paths.php file).
Here is a simple PHP command to test this out:
php -r 'require_once "vendor/autoload.php"; require_once "Net/URL2.php";'
Note: The above command should run without any errors.
Related: Errors in the autoloaded HTTP/Request2 code, how to troubleshoot composer?
You need HTTP_Request2 from git master, because it has not been released/tagged yet at the time of writing.

Autoload Error: No such file or directory

I have included autoload.php in the header of my site
include 'vendor/autoload.php';
From this i am receiving the following errors on my site:
Warning: require_once(DIR/composer/autoload_real.php)
[function.require-once]: failed to open stream: No such file or
directory in
/homepages/6/d416629391/htdocs/leftovercheese/vendor/autoload.php on
line 5
Fatal error: require_once() [function.require]: Failed opening
required 'DIR/composer/autoload_real.php'
(include_path='.:/usr/lib/php5') in
/homepages/6/d416629391/htdocs/leftovercheese/vendor/autoload.php on
line 5
My code is:
// autoload.php generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit8be239f5caef32db03f87bb271ed6012::getLoader();
PHP Version: 5.2.17
Any ideas?
run composer install
That will import your packages and create the vendor folder as well as the autoload script. Also, make sure your relative path is correct.
You have to load vendor/autoload.php, which will autoload that file for you:
require_once __DIR__ . '/vendor/autoload.php';
This is assuming that your file is located at the same directory level as the vendor directory.
Otherwise, adjust.
For me, I updated some folder names and these updated are not reflected in autoload_files.php and autoload_static.php. I just had to run php composer.phar dump-autoload.

Zend - error in index.php - not opening Zend/Application.php

I have a project written in PHP, in zend framework. But when i go on page: localhost/Project/public, i get an error:
Warning: require_once(Zend/Application.php): failed to open stream: No such file or directory in /var/www/Project/public/index.php on line 18 Fatal error: require_once(): Failed opening required 'Zend/Application.php' (include_path='/var/www/Project/library:.:/usr/share/php:/usr/share/pear') in /var/www/Project/public/index.php on line 18
The line 18 in file index.php is following:
require_once 'Zend/Application.php';
I have set include_path in php.ini:
include_path = ".:/usr/share/php:/usr/local/ZendFramework/library"
Zf project is successfully creating by commands from console, so i think that Zend is well configured (anyway in php.ini).
Help me! What I'm doing wrong?
You can see the include path it's using in the error, and it doesn't include /usr/local/ZendFramework/library. Typically index.php overrides the include path to point it at the project's library folder. So either you want a copy of ZF in the library folder, or if you prefer to keep ZF in /usr/local/ you want to edit this include path to point at /usr/local/ZendFramework/library as well.

Zend Failed opening required 'Zend/Loader.php' on Plesk Server

I am getting the following warning and error on a plesk server where I am trying to get the Zend framework working:
PHP Warning: require_once(Zend/Loader.php) [function.require-once]: failed to open stream: No such file or directory in /var/www/vhosts/mydomain.com/httpdocs/test.php on line 5
PHP Fatal error: require_once() [function.require-once]: Failed opening required 'Zend/Loader.php' (include_path='.:/usr/share/pear:/local/PEAR/:/usr/share/zend') in /var/www/vhosts/mydomain.com/httpdocs/test.php on line 5
I have set the include_path in the php.ini file (/etc/php.ini) to use the directory where I have added the Zend files (/usr/share/zend). This directory then has the framework in a sub-dir called Zend.
I have tried adding a slash to the end of the include_path (/usr/share/zend/).
The path is present when I use get_include_path()
I have tried using set_include_path.
The /usr/share/zend directory has 775 permissions (also tried with 777) and the user and group are both set to root.
I would like to have the framework available to all sites on the server.
I have copied in the Gdata files too and the Zend/Loader.php is there.
Versions:
Framework: 2.0.4
Gdata: 1.12.0
This is the PHP:
require_once("Zend/Loader.php");
I have also tried using:
require_once("/usr/share/zend/Zend/Loader.php");
I am novice plesk/unix user
The things to check for are:
The file exists where PHP is looking for it.
The file is readable by the web server/php_fpm process.
safe_mode is off!
(Putting the information here - so that the question can be marked as answered!)
Zend/Loader.php is for ZF1 and that file don't exists with ZF2 (2.0.4)
Also you need to download the updated version of GData compatible with ZF2
https://github.com/zendframework/ZendGData
If you'll use Composer to setup your dependencies then you should use require_once __DIR__ . '/path/to/vendor/autoload.php

Categories