Publish standalone modules on Packagist

Edit on GitHub

To publish a module on Packagist, take the following steps.

Prerequisites

  • Install PHP
  • Install composer

Initialize Composer

  1. Go to the module’s repository directory:
cd my-package
  1. Create composer.json and follow the prompts:
composer init

You’ll be prompted to fill out details like the following:

  • Package name, for example—vendor/package-name
  • Description
  • Author
  • Minimum stability
  • Package type
  • License
  • Optional: Dependencies

Add the package metadata

Add the package metadata to composer.json. Here’s an example of what it might look like:

Make sure all the module dependencies are listed in the `require` section.
{
    "name": "vendor/package-name",
    "description": "A brief description of your package",
    "type": "library",
    "license": "MIT",
    "authors": [
        {
            "name": "Your Name",
            "email": "your-email@example.com"
        }
    ],
    "require": {
        "php": ">=8.1"
    },
    "autoload": {
        "psr-4": {
            "Vendor\\Package\\": "src/"
        }
    }
}

Commit the package to a Git repository

  1. Ignore all the non-module files by creating .gitignore:
# tooling
vendor/
composer.lock
  1. Add all files to the repository:
git add .
  1. Commit the files:
git commit -m "Added composer.json"
  1. Push the changes to the remote repository:
git push -u origin master
  1. Add a new tag in one of the following ways:
  • Recommended: Create a new release using the GitHub web interface. For instructions, see Creating a release.
  • Manually:
git tag v1.0.0
it push origin v1.0.0

Submit the package to Packagist

  1. Go to Packagist.
  2. Log in with your GitHub account or create an account on Packagist.
  3. Once logged in, click Submit.
  4. Enter the URL of your Git repository and click Check.
  5. After the verification, click Submit.

Maintaining your package

Each time you make changes to your package, make sure to push the changes to your Git repository and create a new tag (release).

Updating Composer metadata

As your package evolves, you might need to update your composer.json file with new dependencies or other metadata. After making changes, ensure you commit and push these updates to your Git repository.

Installing the package

To install the published package to a project, run composer require vendor/{package-name}.

Monitoring issues

Monitor the issues reported on your Git repository hosting service and respond to feedback from users to improve your package.