How to use Github as composer package source?

Today we will learn about how we can use github as package source in composer. Composer is a package manager for PHP, all packages that composer have are mostly manged from packagist. We can also use github as package source for composer. Below is the format how we can define a package which source code is available in github to be available to loaded as a composer package.

Composer.json

"require": {
        "lpkapil/phpdocx": "1.0.0"
    },
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "lpkapil/phpdocx",
                "version": "1.0.0",
                "source": {
                    "url": "https://github.com/lpkapil/phpdocx.git",
                    "type": "git",
                    "reference": "master"
                }
            }
        }
    ]
JSON

You need to add have above code snippet in your composer.json file and you can update url (git repo url), reference (git branch) & version (reference version), according to your project.

Once user will run composer install command, it will fetch the package source code in vendor/package-name from reference (git branch) specified in composer.json file.

About Author

Hello, my name is Kapil Yadav. I am a Full stack web developer. I create websites, fix security issues in websites, and create online courses with super easy content so that it flows perfectly with my audience. Lots of love and hundreds of hours went into making it. I hope you love it as much as I do.


Subscribe to my Newsletter to get latest blog updates.

Loading

Leave a Comment

Scroll to Top