Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PHP cannot find the GuzzleHttp\Client class

ErrorClass 'GuzzleHttp\Client' not found

Short answer

PHP only knows GuzzleHttp\Client when the Guzzle package is installed and Composer's autoloader is loaded. Run composer require guzzlehttp/guzzle, make sure vendor/ exists on the server (composer install), and in plain PHP scripts load vendor/autoload.php before you use the class.

  • Applies to Laravel 12, PHP 8.4, Composer 2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask Composer whether Guzzle is part of this project and whether the vendor folder holds it.

    composer show guzzlehttp/guzzle
    ls vendor/guzzlehttp
  2. 2Match what you see, then jump to its fix

    1. 1composer show says the package is not installed, and vendor/guzzlehttp does not existThe Guzzle package is not required by the projectFix
    2. 2composer.json and composer.lock list guzzlehttp/guzzle, but vendor/guzzlehttp is absentThe vendor folder is missing or out of date on this serverFix
    3. 3The error comes from a plain .php file run outside Laravel, and vendor/guzzlehttp existsA standalone PHP script never loads Composer's autoloaderFix

What does the error look like?

  • Class 'GuzzleHttp\Client' not found
  • Class "GuzzleHttp\Client" not found

Cause 1 of 3

The Guzzle package is not required by the project

1Check

Guzzle is a separate package. The code imports it, but composer.json does not list it.

grep -n guzzlehttp composer.json

2Fix

Add it with Composer; this writes it to composer.json and installs it.

composer require guzzlehttp/guzzle:^7.0

3Verify

Composer now shows the package, and the class loads.

composer show guzzlehttp/guzzle

Confirmed by docs.guzzlephp.org

Did this fix it?

Cause 2 of 3

The vendor folder is missing or out of date on this server

1Check

vendor/ is usually not committed. After a deploy or clone, the packages must be installed from composer.lock.

grep -c guzzlehttp composer.lock; ls vendor | head

2Fix

Run install, which reads composer.lock, fills vendor and builds the autoloader. On production add --no-dev.

composer install --no-dev

3Verify

The folder now exists.

ls vendor/guzzlehttp

Confirmed by getcomposer.org

Did this fix it?

Cause 3 of 3

A standalone PHP script never loads Composer's autoloader

1Check

Laravel loads vendor/autoload.php for you. A script run on its own has to do it.

grep -n "autoload.php" script.php

2Fix

Require the autoloader at the top of the script, before the first use of the class.

<?php
require __DIR__ . '/vendor/autoload.php';

$client = new GuzzleHttp\Client();

3Verify

Run the script again.

php script.php

Confirmed by docs.guzzlephp.org

Did this fix it?

How do I stop it coming back?

  • Require every package your code imports, directly, in composer.json.
  • Commit composer.lock and run composer install as a fixed step of each deploy.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.