3

I am working on php with MongoDB. On running the below script in wamp server by going to localhost/test.php, it gives the error:

Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in C:\wamp64\www\test.php on line 3

The second error is

Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='.;C:\php\pear') in C:\wamp64\www\test.php on line 3

I also installed composer by composerSetup.exe. Why it is giving the error?

<?php

require 'vendor/autolod.php';
$client = new Mongo\Client;
$companydb = $client->companydb;
$result1 = $companydb->createCollection('collection1');
var_dump(result1);

?>

while phpinfo() is working fine after running this code.

<?php echo phpinfo(); ?>

Actually I followed this you tube video . He uses XAMP server and run command composer require "mongodb/mongodb=^1.0.0" in xamp/htdocs/projectname/ but I used wampserver and in wamp directory there is no htdocs directory. I think I am making mistake at this point. Is'nt it?

Community
  • 1
  • 1
waqas
  • 143
  • 1
  • 4
  • 15
  • What do you mean when you say you "installed `composer` in this directory"? Did you put a copy of `composer.phar` there? That's one way to install Composer, but it's fine if it lives somewhere else. Did you run `composer install`? That step is much more important. Does `vendor/autoload.php` exist? – ChrisGPT was on strike Aug 21 '16 at 13:59
  • @Chris **1.** I have installed `composer` by `composerSetup.exe` (Question edited) **2.** No I did not put a copy of `composer.phar`. **3.** No, I did not run `composer install`. Where should I install it? **4.** Yes `vendor/autoload.php` exists. – waqas Aug 21 '16 at 14:31
  • Do you have composer.json file in the root directory of your project? – Den Kison Aug 21 '16 at 14:32
  • These two statements seem to be at odds: "No, I did not run `composer install`", "Yes `vendor/autoload.php` exists." Maybe you ran `composer update` instead of `composer install`? Or is your `vendor/` directory tracked by your version control system? – ChrisGPT was on strike Aug 21 '16 at 14:33
  • @Chris Yes I ran `composer require "mongodb/mongodb=^1.0.0"` in cmd. It was successful. – waqas Aug 21 '16 at 14:35
  • 1
    You should look at [basic usage for composer](https://getcomposer.org/doc/01-basic-usage.md) – segFault Aug 21 '16 at 14:45
  • @sebastianForsberg I just saw that `composer.json` exists in my project root directory. – waqas Aug 21 '16 at 14:53
  • @Kison Yes! `Composer.json` exists in root directory that is `C:\wamp64\phpMongoDb\composer.json` – waqas Aug 21 '16 at 14:54
  • Is `vendor/autoload.php` the correct [relative path](https://stackoverflow.com/questions/17407664/php-include-relative-path) to the `autoload.php` file? – ChrisGPT was on strike Aug 21 '16 at 15:03
  • @Chris I am stuck with your link of relative path `https://stackoverflow.com/questions/17407664/php-include-relative-path` What is `_DIR_`? I have not idea about vendor/autoload.php the relative path to `autoload.php` file. – waqas Aug 21 '16 at 15:18
  • @Chris Actually I followed this you tube `https://www.youtube.com/watch?v=9gEPiIoAHo8` video . He uses XAMP server and run command `composer require "mongodb/mongodb=^1.0.0"` in `xamp/htdocs/projectname/` but I used `wamp`server and in `wamp` there is no `htdocs` directory. I think I am making mistake at this point. Is'nt it? – waqas Aug 21 '16 at 15:23
  • @Chris Can you suggest anything? – waqas Aug 21 '16 at 17:22
  • 1
    @waqas, you are trying to include `autoload.php` from a directory called `vendor`. But relative to what? `C:\temp\vendor\autoload.php`? `C:\Users\waqas\Documents\Project\vendor\autoload.php`? You are using a relative path; it might be wrong. [`__DIR__`](https://secure.php.net/manual/en/language.constants.predefined.php) is a magic constant that might be relevant. – ChrisGPT was on strike Aug 21 '16 at 17:32
  • @waqas, how did you fix this problem that I also encountered now? – Pramod Gangadar Nov 13 '22 at 07:07

0 Answers0