How do I create and publish a PHP package to Packagist?

If you want to create and publish a PHP package to Packagist, follow these steps:

Step 1: Create Your PHP Package

First, create a directory for your PHP package and a basic structure for your code.

Step 2: Create composer.json

Inside your package directory, create a `composer.json` file that defines your package metadata and dependencies.

{ "name": "myvendor/mypackage", "description": "An example PHP package.", "require": { "php": "^7.4 || ^8.0" }, "autoload": { "psr-4": { "MyVendor\\MyPackage\\": "src/" } } }

Step 3: Create a Repository on GitHub

Push your package code to a public GitHub repository.

Step 4: Publish to Packagist

Go to Packagist and sign in. Then, submit your GitHub repository URL to add your package to Packagist.


PHP package Packagist PHP composer GitHub package management