Reading list Switch to dark mode

    How to install packages using composer from local git repository

    Updated 5 March 2024

    Composer is tool used to manage dependencies and file autoloading in your PHP project, it simply allows you to download packages from multiple repositories using composer.json file, by default it uses the packagist repository to search and install the packages, but uploading all the projects on packagist and then downloading from there sometimes not feasible, since you just need to test the project if it is working fine when installed from composer, since a huge project can have multiple requirements and dependencies so it is vital to test composer dependencies before offering it to the customer because if your project fails at the time of installation it will create a bad impression.

    Since mostly all the projects are managed on git, svn it will be best to install the packages directly from the local git repository. So let’s see how we can do that, first of all, you need to install composer on your system, please follow this link for installation.

    Composer allows you to define different types of repositories check here

    to allow downloading from local repositories you must use type vcs, which will allow you to install packages directly from the private repository. I will explain the commands that you can use to install packages from local git repo:

    > composer config repositories.repo-name vcs https://git-url/your-package.git
    > composer require company/package:dev-branch-name

    Using above commands you can install from the private git repository, in the above commands the first one is to define the repository url, you can use your local repo file system path or ssh path as well, but to use ssh path you must add your system ssh key your git repo deploy keys, follow this link for better understanding.

    Start your headless eCommerce
    now.
    Find out More

    In the second command we are simply requiring the package with name company/package and to specify the branch name we used dev-branch-name prefix “dev-” is fix and rest is branch name. The sample composer.json in the package will look like this:

    {
      "name":"company/package",
      "description":"this is test package"
    }

    the above is a very basic composer file just to show you the package name, there can be a lot more options.

    Hope this will help you in module development and testing.

    Thanks 🙂 .

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home