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

Pixelairport's avatar

Switch composer package from vcs to path and back

I still try to learn more about composer. I found out how to use "path" type to load local package with symlink in composer. When i do "vcs" type I can load the package from my github account. Now I don't understand how my composer.json should look like.

I want to switch between them, that my local packages still uses my local packages, but when I do "composer install" in production, the packages should be loaded and used in vendor. Is that possible or do I have to change the composer.json each time?

That is what I have for local package:

{
            "type": "path",
            "url": "packages/pixelairport/platform-api2",
            "options": {
                "symlink": true
            }
        }

And that is what I need for production.

        { "type": "vcs", "url": "https://github.com/pixelairport/platform-api2.git" },

How can I have both in one composer.json that the local version is maybe only used when the directory exists?

....

0 likes
7 replies
Robstar's avatar

Note sure why you need that as VCS? Can;t you remote the VCS block and do a:

composer require pixelairport/platform-api2

Pixelairport's avatar

Maybe I don't understand it right. I want to develop my own package. I also build a main application, which i will use for every other application in the future. It loads everything I use all the time. When I install it locally it should also load the dependencies from github (my own package). But when I decide to change something in the package I want to clone it into packages folder and make my changes. Then I deploy it. In this situation the package from my packages directory should be used.

Or is there a better workaround? Thx.

Pixelairport's avatar

... I use now symlinks locally to develop my packages. But what if I deploy the whole application? In production composer should use the version from vendor directory. But i wont update my composer.json everytime when i deploy my main applicaiton. Hope somebody can help me. Thx.

Robstar's avatar

@PIXELAIRPORT - Yep, that's composer. You have a package which is an isolated piece code of code spearate to your main application.

For example, https://github.com/symfony/console is a package that allows you to interact with the console. You'd run composer require symfony/console to include it in your app.

The package above could be your own package, the principal is the same.

The only additional consideration if you want your own packages to be private i.e. not usable by others.

1 like
Pixelairport's avatar

Thx @robstar did it first with path type, but now it seems i found the best solution for me:

  { "type": "git", "url": "https://github.com/pixelairport/platform-api2.git" }

This loads the package from github with .git files to push changes back. But one last thing does not work. I have this in my composer

 "extra": {
        "branch-alias": {
            "dev-master": "1.0-dev"
        },
        "laravel": {
            "providers": [
                "Pixelairport\PlatformApi2\Providers\ApiProvider"
            ]
        }
    },

But my ApiProvider is not booted or registered when load my application. Is this not possible with type git?

Pixelairport's avatar
Pixelairport
OP
Best Answer
Level 12

It works :) This is how i load my package from git.

{
            "type":"package",
            "package": {
                "type": "package",
                "name": "pixelairport/platform-api2",
                "version":"1.0",
                "source": {
                    "url": "https://github.com/pixelairport/platform-api2.git",
                    "type": "git",
                    "reference":"1.0"
                },
                "autoload": {
                    "psr-4": {
                        "Pixelairport\PlatformApi2\": "src"
                    }
                }
            }
        }

I also set the psr-4 for my autoloader. it seems when it is not a composer package from packagist, it dont use the composer file of the package. So i do it here. Not sure if I'm wrong. I just write it if someone else have the problem. Maybe this helps...

To load a provider I had to add it in config/app.php because of the not loaded composer file. Here is the post where i read it: https://likegeeks.com/install-and-use-non-composer-laravel-packages/

Thx also @robstar for your help. Now it works like I hoped it would be.

Please or to participate in this conversation.