0

I'm having a problem with vlucas/phpdotenv installation

 ~/ nslookup repo.packagist.org
Server:     8.8.8.8
Address:    8.8.8.8#53

Non-authoritative answer:
Name:   repo.packagist.org
Address: 54.37.2.184

My composer.json:

{
    "name": "developer/mvc",
    "authors": [
        {
            "name": "Abubakr Abduvakhidov",
            "email": "abubakr@edu.thedevs.co"
        }
    ],
    "autoload": {
        "psr-4": {
            "app\\": "."
        }
    },
    "require": {}
}

Output of composer diagnose:

Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 2.0.8
PHP version: 7.4.12
PHP binary path: /usr/local/Cellar/php/7.4.12/bin/php
OpenSSL version: OpenSSL 1.1.1h  22 Sep 2020
cURL version: 7.73.0 libz 1.2.11 ssl OpenSSL/1.1.1h
zip: extension present, unzip present

When I run this command:

composer require vlucas/phpdotenv -vvv

I get the following output:

Loading config file /Users/abubakr/.composer/config.json
Loading config file /Users/abubakr/.composer/auth.json
Failed to initialize global composer: Composer could not find the config file: /Users/abubakr/.composer/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Running 2.0.8 (2020-12-03 17:20:38) with PHP 7.4.12 on Darwin / 20.1.0
Loading config file /Users/abubakr/.composer/config.json
Loading config file /Users/abubakr/.composer/auth.json
Failed to initialize global composer: Composer could not find the config file: /Users/abubakr/.composer/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Reading ./composer.json
Loading config file /Users/abubakr/.composer/config.json
Loading config file /Users/abubakr/.composer/auth.json
Loading config file ./composer.json
Checked CA file /usr/local/etc/openssl@1.1/cert.pem: valid
Executing command (/Users/abubakr): git branch -a --no-color --no-abbrev -v
Executing command (/Users/abubakr): git describe --exact-match --tags
Executing command (CWD): git --version
Executing command (/Users/abubakr): git log --pretty="%H" -n1 HEAD --no-show-signature
Executing command (/Users/abubakr): hg branch
Executing command (/Users/abubakr): fossil branch list
Executing command (/Users/abubakr): fossil tag list
Executing command (/Users/abubakr): svn info --xml
Failed to initialize global composer: Composer could not find the config file: /Users/abubakr/.composer/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Downloading https://packagist.phpcomposer.com/packages.json
[200] https://packagist.phpcomposer.com/packages.json
Writing /Users/abubakr/.composer/cache/repo/https---packagist.phpcomposer.com/packages.json into cache
Downloading https://packagist.phpcomposer.com/p2/vlucas/phpdotenv.json
[404] https://packagist.phpcomposer.com/p2/vlucas/phpdotenv.json
Downloading https://packagist.phpcomposer.com/p2/vlucas/phpdotenv~dev.json
[404] https://packagist.phpcomposer.com/p2/vlucas/phpdotenv~dev.json
Downloading https://packagist.org/search.json?q=vlucas/phpdotenv&type=
[200] https://packagist.org/search.json?q=vlucas/phpdotenv&type=

                                                                               
  [RuntimeException]                                                           
  No composer.json present in the current directory, this may be the cause of  
   the following exception.                                                    
                                                                               

Exception trace:
 () at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/src/Composer/Command/RequireCommand.php:193
 Composer\Command\RequireCommand->execute() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/vendor/symfony/console/Command/Command.php:245
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/vendor/symfony/console/Application.php:835
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/vendor/symfony/console/Application.php:185
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/src/Composer/Console/Application.php:310
 Composer\Console\Application->doRun() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/src/Composer/Console/Application.php:122
 Composer\Console\Application->run() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/bin/composer:63
 require() at /usr/local/Cellar/composer/2.0.6/bin/composer:24

                                            
  [InvalidArgumentException]                
  Could not find package vlucas/phpdotenv.  
                                            
  Did you mean one of these?                
      vlucas/phpdotenv                      
      sobyte/dotenv-php                     
      calgamo/module-php-dotenv             
      abacaphiliac/zend-phpdotenv           
      davek1312/config                      
                                            

Exception trace:
 () at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/src/Composer/Command/InitCommand.php:796
 Composer\Command\InitCommand->findBestVersionAndNameForPackage() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/src/Composer/Command/InitCommand.php:430
 Composer\Command\InitCommand->determineRequirements() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/src/Composer/Command/RequireCommand.php:189
 Composer\Command\RequireCommand->execute() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/vendor/symfony/console/Command/Command.php:245
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/vendor/symfony/console/Application.php:835
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/vendor/symfony/console/Application.php:185
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/src/Composer/Console/Application.php:310
 Composer\Console\Application->doRun() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/src/Composer/Console/Application.php:122
 Composer\Console\Application->run() at phar:///usr/local/Cellar/composer/2.0.6/bin/composer/bin/composer:63
 require() at /usr/local/Cellar/composer/2.0.6/bin/composer:24

require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--fixed] [--no-suggest] [--no-progress] [--no-update] [--no-install] [--no-scripts] [--update-no-dev] [-w|--update-with-dependencies] [-W|--update-with-all-dependencies] [--with-dependencies] [--with-all-dependencies] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--] [<packages>]...

And I expected this to happen: package to be installed

Additional:

 /Applications/XAMPP/xamppfiles/htdocs/php/mvc/ [master+*] which composer
/usr/local/bin/composer
 /Applications/XAMPP/xamppfiles/htdocs/php/mvc/ [master+*] alias | grep composer

 /Applications/XAMPP/xamppfiles/htdocs/php/mvc/ [master+*] ls
composer.json  core           models         vendor
composer.lock  migrations     public         views
controllers    migrations.php runtime

1 Answers1

0

Actually, it was because of loading metadata from https://packagist.phpcomposer.com/packages.json, which is not the official Packagist, but an official mirror (and a broken one according to the list in https://github.com/Webysther/packagist-mirror#-packagist-public-metadata-mirrors-observatory-around-the-world)

That's probably the reason for the issue: the package is not found in the metadata in this repository, but the repository still exposes the official search endpoint instead of a mirrored one, which is used by composer when looking for alternative names.

After running the command in the bottom it started downloading

composer config -g repo.packagist composer https://packagist.org