Problems configuring Composer with XAMPP in Windows environment

Asked

Viewed 1,981 times

6

Installing Composer in windows has given me some work. I have some doubts:

The Composer installer on Windows asks to inform the location of php.exe, and settle in there. After that I ran the commands on my console composer.json is like this:

{
    "require": {
        "guzzlehttp/guzzle": "~5.2"
    }
}

The composer.Lock and the autoload.php were created after installation everything correct. When using in my file if I indicate :

require_once 'vendor/autoload.php';

It will not work because the vendor folder is in C:\XAMPP\PHP and the project in C:\XAMPP\HTDOCS\Site.

I tried to indicate in require the full vendor path (C:\XAMPP\PHP\Vendor\autoload.php) didn’t work either.

Does anyone know where I am going wrong? If it is otherwise that informs where the autoload is?

  • Have you tried putting the directory where Composer and PHP are in your environment variable PATH? So you can call them anywhere.

  • The archive composer.json must be in the root folder of your project (C: XAMPP HTDOCS Site)

  • @luciorubenns Then I think there’s something wrong,

  • When rotating composer update in the project folder, which output?

  • @luciorubeens Loading Composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files

  • The briefcase vendor and the file composer.lock were also generated in the project folder?

  • @luciorubeens Positivo

  • @Rodolfooliveira As mentioned, you should always use Composer install/update in your project folder, just as the Composer.json file should be there as well. And how are you able to use Composer and autoload?

Show 3 more comments

1 answer

5


You are confusing things.

Composer is a project-level package manager. You will not create a file composer.json in your PHP folder, but in the folder of each project:

Project directory before the composer install / update:

Diretório antes do composer install

When executing the command on our terminal, Composer will download the dependencies ...

composer update console

... and will create the folder vendor along with the dependencies of your composer.json

Pastas do Projeto

Now yes, include the vendor/autoload.php to use the dependencies of your project. Remember that the path is relative to root of your project.

index php.

<?php

require_once 'vendor/autoload.php';

use GuzzleHttp\Client;    
$client = new Client();
  • Perfect. The point is exactly this: the dependencies are at the project level, so the files composer.json and composer.lock must be versioned together with your project.

  • It is possible to use global dependencies (phpunit, phpspec) to use via the command line, but that is another matter.

  • Obrigad.I had never used Composer before, what was missing was "use Guzzlehttp Client"

  • @Rodolfooliveira this use is to inform you that when you use a class Client it search in namespace GuzzleHttp. Another way would be to use the full path new GuzzleHttp\Client, but this can become repetitive.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.