Share a PHP package with Composer and Packagist

Hi there! In this quick tutorial we will see how to create a package for your PHP class/library with composer and publish it on packagist.org.

You probably are already using composer to manage dependencies in your projects and search for packages to speed up your development.

And guess what… creating your packages and giving back to the PHP community is as easy as requiring them!

Before we start…

(Skip this part if you already have composer installed and you project code on a version control system)

Installing composer

You will need composer installed on your system to create and test your packages so, if you don’t have it already, let’s go ahead and install it.

I recommend you install composer globally so then you can access it in any directory by just typing composer:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

# After it finishes, test it!
composer --version

Although, if you are on windows or just want a to install composer locally for your project, you can check their quick start guide.

Continue reading