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':
Related
I have inherited an old legacy system based off Yii 1.1 which has had multiple development teams working on it for the past 10 years so is a bit of a mess with little to no documentation.
Doctrine Migrations have been used in the past and I can get this working on Docker, however on the live EB/EC2 instance, the migrations files will not run from command line.
Command:
php vendor/bin/doctrine-migrations status
Throws error
PHP Warning: require(/var/app/current/site/vendor/bin/doctrine-migrations.php): failed to open stream: No such file or directory in /var/app/current/site/vendor/bin/doctrine-migrations on line 8
PHP Fatal error: require(): Failed opening required '/var/app/current/site/vendor/bin/doctrine-migrations.php' (include_path='.:/usr/share/pear7:/usr/share/php7') in /var/app/current/site/vendor/bin/doctrine-migrations on line 8
Looking at my local environment versus the live server, no doctrine-migrations.php file has been created in vendor/bin on the dev server, which composer should have created and is the file being looked for. Composer install is run during build on every deployment but I can't figure out why it is not auto-generating this file in the vendor/bin directory - just another file called doctrine-migrations which pretty much just requires doctrine-migrations.php:
#!/usr/bin/env php
<?php
declare(strict_types=1);
namespace Doctrine\Migrations;
require __DIR__ . '/doctrine-migrations.php';
conposer install install bundle declared in your composer.lock file.
Your composer.lock file is generated when doing your first composer install or a composer update or composer require
Difference may occur between your local environment and production environment.
Indeed, on local, composer install install some bundle only needed in dev mode (see your require-dev part in composer.json)
Either the composer.lock file is not up to date with your composer.json file (if composer.json contain the required bundle) either the required bundle is set as require-dev
To install it, you can run composer install doctrine/doctrine-migrations-bundle
I'm trying to install the Drupal Console (https://drupalconsole.com/)
As per the instructions here:
https://hechoendrupal.gitbooks.io/drupal-console/content/en/getting/windows.html
I have Git for windows, composer, PHP, and sqlite-tools-win32-x86 all
installed.
I have defined everything as per the instructions on that page.
When I run:
$ composer global require drupal/console:#stable
I'm getting:
admin#Dxxx MINGW64 ~
$ composer global require drupal/console:#stable
Changed current directory to C:/Users/admin/AppData/Roaming/Composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
That lead me to look into the composer settings. When i run
$ composer -d
I get:
[RuntimeException]
Invalid working directory specified, does not exist.
Looks like something is wrong with my composer installation. Any idea what?
I have a git repository which is a simple cakephp3 application. (i cant share because that is private).
i forked the repository and cloned it to my local directory, but as i open the url it gives me this error:
Warning: require(C:\xampp\htdocs\cakephp\shopinator\sms\smsv3\vendor\autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\cakephp\shopinator\sms\smsv3\config\bootstrap.php on line 23 Fatal error: require(): Failed opening
required 'C:\xampp\htdocs\cakephp\shopinator\sms\smsv3\vendor\autoload.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\cakephp\shopinator\sms\smsv3\config\bootstrap.php on line 23
I also have composer installed and is recognizable. I'm using git bash.
the same repository is running fine on another machine.
Any help would be appreciated.
Update:
I've tried it this way:
I'm installing cakephp 3 using composer, it still gives me the same error.
composer create-project cakephp/app
I've also tried this but no luck.
Update:
with this command
composer create-project --prefer-dist cakephp/app
the fresh installation worked.
I've solved the problem.
I downloaded the composer.phar file from packagist.org
and executed the following commands in my application root.
php composer.phar install
Now i don't have that autoload.php issues.
I know many users have asked same question before but it wasn't helpful for me...
I have a VPS (centOS6.5/directadmin/php5.4/SSH terminal)
I try install imagine (https://imagine.readthedocs.org) class in my server via getcomposer.org
These are my all steps:
First I install getcomposer:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
then:
cd /usr/local/bin/
And
echo '{"require": {"imagine/imagine": "~0.6.2"}}'->composer.json
After That I run it:
composer update
OK! everything seems installed!
Now in my website root, I want to test it:
<?php
require 'vendor/autoload.php'; // line 2
$imagine = new Imagine\Gd\Imagine(); // line 3
?>
But I get this error:
Warning: require(vendor/autoload.php): failed to open stream: No such
file or directory in
/home/admin/domains/example.com/public_html/info.php on line 2
Fatal error: require(): Failed opening required 'vendor/autoload.php'
(include_path='.:/usr/local/php54/lib/php') in
/home/admin/domains/example.com/public_html/info.php on line 2
//EDIT
The real locate of autoload.php in my server:
/usr/local/bin/vendor/autoload.php
Also There "imagine" directory in vendor directory!
/usr/local/bin is where your binary files live. You should move composer.phar to this location (and rename it to composer) and then use composer in your command line.
The composer.json file is part of your package, it specifies the packages it depends on in this file. You then can install all required packages for the current package by using composer install/composer update. This will make a vendor directory with all third party code and a preconfigured autoloader in vendor/autoload.php.
Finaly after install imagine class, I moved the composer to root of my website and now it works normally
I'm trying to make a little CLI tool and package it up with composer.
Below is an extremely simplified version of the program, but it's enough to demonstrate the problem I'm encountering.
The project has one dependency, and one "binary" file
composer.json
{
"name": "alice/yamldump",
"version": "0.2.0",
"bin": [
"bin/yamldump"
],
"require": {
"symfony/yaml": "2.5.3"
}
}
bin/yamldump
#!/usr/bin/env php
<?php
// use Yaml namespace
use Symfony\Component\Yaml as Yaml;
// autoload
require_once "vendor/autoload.php";
// read yaml
$yaml = file_get_contents(sprintf("%s/%s", getcwd(), $argv[1]));
// create parser
$parser = new Yaml\Parser();
// parse the yaml
var_dump($parser->parse($yaml));
So when I install it globally, I get this
$ composer global require alice/yamldump=dev-master
Files are installed to
~/.composer/vendor/bin/yamldump -> ../alice/yamldump/bin/yamldump
~/.composer/vendor/alice/yamldump/
~/.composer/vendor/symfony/yaml/
This is a problem, because I did not intend to globally install symfony/yaml and my package's vendor/autoload.php can no longer find the Yaml package in the proper location.
I don't mind that symfony/yaml was installed globally, but it would make sense to me that composer global require would install the package like this:
~/.composer/vendor/bin/yamldump -> ../alice/yamldump/bin/yamldump
~/.composer/vendor/alice/yamldump/
~/.composer/vendor/alice/yamldump/vendor/symfony/yaml/
After all, what if I have Package A that depends on symfony/yaml=2.5.3 and Package B that requires symfony/yaml=2.6.x?
If the composer global require installs dependencies to ~/.composer/vendor/*, each globally required package can't maintain it's own version requirement of its dependency...
I know this is sort of a convoluted problem, but I really don't know how to begin fixing it.
The goal
A user should be able to
$ composer global require alice/yamldump=dev-master
$ yamldump sample.yml
The error
$ yamldump sample.yml
Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in /Users/alice/.composer/vendor/alice/yamldump/bin/yamldump on line 8
Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.:') in /Users/alice/.composer/vendor/alice/yamldump/bin/yamldump on line 8
The question
Here it is in black & white:
How am I intended to write the require "vendor/autoload.php" line and have it work for both locally installed packages and globally installed packages?
Targeting vendor/autoload.php is generally not a good idea and only works if you run the script from the correct directory. The following should serve you better:
require_once __DIR__.'/../vendor/autoload.php';
However, this still might be an issue if your application is installed as a dependency. In that case, you might need something more substantial:
if (
(!$classLoader = includeIfExists(__DIR__.'/../vendor/autoload.php')) &&
(!$classLoader = includeIfExists(__DIR__.'/../../../autoload.php'))
) {
echo 'You must set up the project dependencies, run the following commands:'.PHP_EOL.
'curl -sS https://getcomposer.org/installer | php'.PHP_EOL.
'php composer.phar install'.PHP_EOL;
exit(1);
}
This first looks for the autoloader in the location you would expect it to be if you are working directly on your application. If that does not exist, it looks where the autoloader would be if your application is installed as a dependency.