Publishing to Packagist

Keep on Learning!

If you liked what you've learned so far, dive in!
Subscribe to get access to this tutorial plus
video, code and script downloads.

Start your All-Access Pass
Buy just this tutorial for $8.00

With a Subscription, click any sentence in the script to jump to that part of the video!

Login Subscribe

Our bundle is ready to be shared with the world! So let's take care of a few last details, and publish our bundle to Packagist!

Choosing a License

But, before we publish this anywhere, we need do some boring, but very important legal work. Go to and find the license that works best for you. Symfony is licensed MIT, and that's definitely the best practice. Whatever you choose, copy the license, find your bundle code, and at the root, create the LICENSE file.

MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

Pushing to GitHub

Legal stuff, done! Next, find your terminal: there are a bunch of uncommitted changes. Oh, before we add them, I made a mistake!

I have an extra tests/Controller/cache directory! Open IpsumApiControllerTest and find the getCacheDir() method. I meant to change this to use the same cache directory as FunctionalTest, which is already set to be ignored by git. Add a ../ to the path. Then, delete the extra cache/ dir. There's also an extra logs directory, but it's empty, so just ignore it.

... lines 1 - 26
class KnpULoremIpsumControllerKernel extends Kernel
... lines 29 - 55
public function getCacheDir()
return __DIR__.'/../cache/'.spl_object_hash($this);

Now move back to your terminal, add everything to git, give it an inspiring message, and commit!

With everything committed, let's push this to GitHub! Well, you can host it anywhere, but GitHub is the most common place. I'll click "New Repository", choose the KnpUniversity organization, and name it lorem-ipsum-bundle.

It's not required, but it's usually nice to name the repository the same as the package name in composer.json. Give it a clever description, make sure it's public, and create repository!

Copy the code to push to an existing repository, go find your terminal, quick! Paste, hit enter, wait impatiently... then... say hello to our new repository!

Registering on Packagist

With that done, we can now put our bundle up on Packagist! Go to and make sure you're logged in. Then, it's super easy: click "Submit", copy the GitHub URL, paste, and click "Check".

This does some sanity checks in the background, like parsing your composer.json file and waiting for Jordi to search for any similar packages on Packagist, to help avoid duplication.

Looks ok! Moment of truth: Submit!

Boom! We are a package!

Auto-updating with the GitHub Service Hook

Oh, but notice this message:

The package is not auto-updated. Please setup the Github Service Hook

This is actually important. When we create a new tag in GitHub, we want Packagist to automatically see it.

Go back to GitHub, click Settings, Integration & services, "Add service" and find Packagist. You'll need to enter your username and a token you can find on your Packagist profile page. Then, add service!

Requiring the new Package

And, for now, we're done! We have a real package! Next, open our application's composer.json file. We're still using this path repository option. Let's finally install our package properly. Remove the repositories section.

Then, go to the terminal for your app, and, first, remove the current package:

composer remove knpuniversity/lorem-ipsum-bundle

Gone! And thanks to the Flex recipe, it also removed the bundle from bundles.php. Cool!

Now, lets re-install it:

composer require knpuniversity/lorem-ipsum-bundle

This downloads dev-master, so the master branch, because there's no tag yet. And! Flex re-added the bundle to bundles.php.

Writing a Decent README

Cool! But, go back to the GitHub page for our bundle. See anything missing? Yea, no README! That's not ok! If you go back to the "Symfony bundle best practices" page, this has an example README you can use to get started.

Head back to our code, I'll close a few files, then create a new file. And, bam! I just wrote us a README file!

# Hello LoremIpsumBundle!
LoremIpsumBundle is a way for you to generate "fake text" into
your Symfony application, but with *just* a little bit more joy
than your normal lorem ipsum.
Install the package with:
composer require knpuniversity/lorem-ipsum-bundle --dev
And... that's it! If you're *not* using Symfony Flex, you'll also
need to enable the `KnpU\LoremIpsumBundle\KnpULoremIpsumBundle`
in your `AppKernel.php` file.
## Usage
This bundle provides a single service for generating fake text, which
you can autowire by using the `KnpUIpsum` type-hint:
... lines 21 - 94

Don't worry, I'm not going to lecture you on how to write README files. Well, actually, can I take just one minute to point out the most important parts that I think people sometimes forget?

To start, make sure your bundle has these four parts. One, at the top, say what the bundle does in plain language! Two, show the composer require installation command. Three, give a simple usage example, before talking about any other technical jargon. And four, show the configuration.

After that, you can talk about whatever complex or theoretical stuff you want, like how to create a word provider.

Also, when you create code examples, there are two common mistakes. First, make sure you include the file path as a comment: people don't always know where a file should live. Second, don't create the code blocks here. Believe me, you'll make a mistake. Code them in a real app, paste them here, then tweak.

Oh, and for the configuration section, remember, you can run:

php bin/console config:dump knpu_lorem_ipsum

to get a full config tree to paste here. Oh, and, if the user needs to create a file - like knpu_lorem_ipsum.yaml, say that explicitly: sometimes people think they're doing something wrong if a file doesn't already exist.

A Recipe?

The last thing I would recommend is, if it makes sense, create a recipe for your bundle. Do this at We're not going to do this, but if your bundle needs a config file or any other setup, this is a huge way to make it easier to use.

If you don't create a recipe, Flex will at least enable the bundle automatically. And in a lot of cases - like for this bundle - that's enough.

Ok, just one topic left, and it's fun! Let's setup continuous integration on Travis CI so that we can be sure our tests are always passing.

Leave a comment!

  • 2020-02-12 weaverryan

    Hey Слава Лаптев!

    Well, the type key looks perfect :). Here is the logic in Symfony Flex that automatically updates bundles.php when it's installing a "symfony-bundle" type:

    For this to work, you need a few things:
    A) The symfony-bundle type
    B) Flex needs to be able to *locate* your bundle class

    My guess is that (B) is not working. Flex looks in some "common" places for your "bundle" file and follows some conventions to find it. The logic is here:

    This looks at your psr-4 path (so, src/ in your case) then uses your namespace to try to find the correct bundle class there. I'm not actually sure all the things it "tries" - the logic is in the extractClassNames() method that it calls. I would add some var_dump inside that method and install your bundle to see what class names it's looking for. It's possible that your bundle class (or file path) is not what Flex is expecting, so it can't "guess" it and install it.

    Let me know what you find out!


  • 2020-02-12 Слава Лаптев

    "name": "company/name",
    "description": "some test",
    "type": "symfony-bundle",
    "license": "proprietary",
    "require": {
    "php": "^7.1.2",
    "ext-ctype": "*",
    "ext-iconv": "*",
    "symfony/config": "4.4.*",
    "symfony/dependency-injection": "4.4.*",
    "symfony/http-kernel": "4.4.*",
    "symfony/yaml": "4.4.*",
    "symfony/serializer": "4.4.*",
    "symfony/form": "4.4.*"
    "autoload": {
    "psr-4": {
    "Mokryinos\\ServiceResponseBundle\\": "src/"
    "conflict": {
    "symfony/symfony": "*"

    my composer.json in bundle

  • 2020-02-10 Diego Aguiar

    Ohh, it's your own bundle. It may be missing the "type" key on your composer.json. Check at this piece of documentation:


  • 2020-02-08 Слава Лаптев

    I try install my bundle, from private bitbucket repository, In my project Flex installed, because other bundles registred, after composer required

  • 2020-02-05 Diego Aguiar

    Hey Слава Лаптев

    Can you tell me what bundle is not being registered? Also, could you double check that Symfony Flex is installed in your project?
    When you install a bundle that comes with a recipe, you should see a message coming from Composer that a recipe was found


  • 2020-02-05 Слава Лаптев

    Can you help?
    In my case symfony flex doesn't enable bundle in bundles.php.
    I can't understand why? Maybe you can suggest me a reason.
    I use symfony 4.4

  • 2019-11-06 Victor Bocharsky

    Hey Sela,

    As an author of the bundle, you have access to its Git repository, right? So, just push your changes to that repo. If you would like to do some changes in the bundle in a real project - you can install the bundle from the local Git repository with Composer. Then it will be symlinked, so when you will change code in your bundle's local repository - you will see the changes in your project. See Composer docs for more information on it: .

    As an alternative solution, Composer allow you to install packages from source, use "composer install --prefer-source" and Composer, instead downloading just files, will pull down the entire Git repositories, but the previous solutions might be better I think :) And actually exactly this solution we show in this course, see . Have you seen that chapter? :)

    I hope this helps!


  • 2019-11-05 Sela Yair

    How do you keep updating the bundle once it's in Packagist? I mean the code now is in /vendor how do I manage to have the GIT?