Publish standalone modules on Packagist
Edit on GitHubTo publish a module on Packagist, take the following steps.
Prerequisites
- Install PHP
- Install composer
Initialize Composer
- Go to the module’s repository directory:
cd my-package
- 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:
{
"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.2"
},
"autoload": {
"psr-4": {
"Vendor\\Package\\": "src/"
}
}
}
Commit the package to a Git repository
- Ignore all the non-module files by creating
.gitignore
:
# tooling
vendor/
composer.lock
- Add all files to the repository:
git add .
- Commit the files:
git commit -m "Added composer.json"
- Push the changes to the remote repository:
git push -u origin master
- 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
- Go to Packagist.
- Log in with your GitHub account or create an account on Packagist.
- Once logged in, click Submit.
- Enter the URL of your Git repository and click Check.
- 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.
Thank you!
For submitting the form