DEV Community

Cover image for Publish a PHP library to Packagist 📦
Pierre-Henry Soria ✨
Pierre-Henry Soria ✨

Posted on • Updated on

Publish a PHP library to Packagist 📦

Today, we are looking on how to publish a PHP Composer v1 and v2 package to packagist.org 😊

1. Your library has to contain a .composer.json

When you create your library, run a composer init to generate a composer.json file containing your details as well as a vendor name and the library name of your package you will publish to the Packagist registry.

The information in there as well as the information of your README.md file (located in the root of your project) will be used by packagist.org to show the information about your library.

2. GitHub account (or other git hosting platform)

Make sure you have an account n GitHub (or on a similar platform such as GitLab or Butbucket).

3. git push to your remote Git repository (e.g. GitHub)

Publish your code to GitHub or on a similar platform (e.g. GitLab, Butbucket or on your own server).

4. Create an account on packagist

You will need an account on packagist.org in order to publish your package.

5. Submit your package

Now, you will need to submit your new package by clicking on the "Submit" button.

You will need to mention the Repository URL. Your repository URL is foundable on the repository page of your git hosting platform, on the "Clone" section. It looks like https://github.com/{username/{project-name}.git

Submit PHP Composer package to Packagist

Once submitted, you will be redirected to the detail page of your library.
Packagist library page details

If you didn't create a git tag yet, the default version of your library will be dev-master.

Default release master dev packagist php

Once you create a git tag release (can be also done through GitHub, Releases -> Draft a new release), the version will be the new one set as default.

create tag on GitHub

dev master release git tag

6. 🏆 Well done 🐘

You are all set and your library is ready to be used and installed by anyone, simply with composer require {your-vendor-name}{your-librar-name}


Top comments (2)

Collapse
 
pierre profile image
Pierre-Henry Soria ✨

By the way, if this could interest you, I’ve also published a Udemy course teaching how to build a real-example PHP 8 application from scratch - udemy.com/course/create-real-world...

As always, any feedback/thoughts welcome! 🤗

Collapse
 
pierre profile image
Pierre-Henry Soria ✨

Hey hey 🤗, let me know any questions or feedback if any 😉