How to publish your first composer package? 🐘

Atakan Demircioğlu
Developers Keep Learning
2 min readFeb 18, 2023

--

In this article, I will try to explain how to publish your first composer package.

If you guys don’t know actually what is a composer, let us first explain “What is composer?”.

The Composer is a tool for dependency management in PHP. Just it.

Create composer.json

  • Firstly be sure you installed composer. Here is the official page of the composer.
  • Create a repository in GitHub.
  • Create composer.json at the top level of the repository. Or you can use composer init is a little bit similar to npm init and you can use the quick template.

Here is the composer.json of atakde/php-rate-limiter.

  • Be sure to fill in keywords, descriptions, and authors. If you use the composer init command, you can get some tips when creating the composer.json file.
  • require part & require-dev are for managing your packages. It is not basically different from an npm package.
  • Be careful about the autoload part. For a better understanding of PSR-4 Autoloader please check here.

Register Packagist

Go to Packagist official page and register. Here is the official link of Packagist.

Before submitting your package, you need to create a tag and release in GitHub.

git tag 1.0.0
git push origin 1.0.0
gh release v1.0.0

After that go to submit page.

You will see a similar screen like that. (In the future it can be changed)

Then submit your repository. That’s it.

You can check the published package example here. For checking code, here you can find the GitHub repository.

Testing the package

After being added, let’s check it.

composer require "atakde/php-rate-limiter"

If you see similar output, congrats you have successfully published your PHP package.

If you like to get more updates from me, 
please follow me on Medium and subscribe to email alert.

--

--

Atakan Demircioğlu
Developers Keep Learning

Passionate about blogging and sharing insights on tech, web development, and beyond. Join me on this digital journey! 🚀