Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

How to tell Composer to install from my added repository?

I added my repository to composer.json:

    "repositories": [
        {
            "type": "composer",
            "url": "http://localhost/"
        }
    ],

And then added some random package to the require block, in this case doctrine/inflector:

    "require": {
        "php": "^8.0.2",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^9.19",
        "laravel/sanctum": "^3.0",
        "laravel/tinker": "^2.7",
        "doctrine/inflector": "2.0.4"
    },

Then I deleted it from vendor, deleted composer.lock and ran composer install. But the new composer.lock still has the GitHub url of this package instead of my localhost:

            "name": "doctrine/inflector",
            "version": "2.0.4",
            "source": {
                "type": "git",
                "url": "https://github.com/doctrine/inflector.git",               
            },

How can I make Composer install packages from my localhost repository?

0 likes
4 replies
Ligonsker's avatar

@Tray2 I actually managed to make it work eventually when adding the repository. But the problem is, that when I explicitly specify a local repository, then if it's offline, Composer won't fallback to default sources like GitHub or Packagist. Instead, it throws errors.

In my case I shut down my local repo server then ran composer install, but got:

curl error 7 while downloading http://localhost/packages.json: Failed to connect to localhost port 80: Connection refused

But it did not continue to install from Packagist or GitHub as it normally does when the repositories block is not there

Ligonsker's avatar

@Sinnbeck I did not have the chance to try it since from some reason it started working and now it's a different message, installing from source:

    Failed to download doctrine/inflector from dist: The "http://localhost//dist/doctrine/inflector/doctrine-inflector-2.0.4-68353b.zip" file could not be written to C:\tests\test/vendor/composer/tmp.zip: Failed to open stream: Permission denied
    Now trying to download from source

Now it was permission denied instead of curl error 7, but I think your solution would've also solved it

Please or to participate in this conversation.