简体   繁体   中英

'vendor/autoload.php' errors, composer is installed globally

I installed composer globally and when I run my mail php example I get the following errors:

Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/emailexample/index.php on line 9

Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/emailexample/index.php on line 9

I appreciate any advice on resolving these errors.

I'm afraid you misunderstood what Composer is and what installing it globally means. Composer is a tool for installing dependencies in your project. Installing it globally means that you can use this tool from any place in your system, but it doesn't mean that it will magically resolve all dependencies from all of your project - you need to call Composer manually to declare and install required dependencies.

So if you have composer.json file in /Applications/XAMPP/xamppfiles/htdocs/emailexample you should go into your project directory and install required dependencies:

cd  /Applications/XAMPP/xamppfiles/htdocs/emailexample
composer install

If you don't have composer.json you need to define your dependencies first. You can read more about it in documentation , and dependencies should be defined in source of your "mail php example" project. But in general you can add dependencies by:

cd  /Applications/XAMPP/xamppfiles/htdocs/emailexample
composer require package/name

Where package/name is name of dependency - you should replace it with real name.

After installing dependencies make sure that you include composer autoloader in your index.php - you should have something like this before using any class:

require_once __DIR__  . '/vendor/autoload.php':

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM