let us create a simple extension displaying a standard “hello world” message. this extension will be distributed via the packagist repository.
step 1 − create a folder called hello-world in your hard drive but not inside the yii basic application template). inside the hello-world directory, create a file named composer.json with the following code.
{
    "name": "tutorialspoint/hello-world",
    "authors": [
        {
            "name": "tutorialspoint"
        }
    ],
    "require": {},
    "autoload": {
        "psr-0": {
            "helloworld": "src/"
        }
    }
}
we have declared that we are using the psr-0 standard and all extension files are under the src folder.
step 2 − create the following directory path: hello-world/src/helloworld.
step 3 − inside the helloworld folder, create a file called sayhello.php with the following code.
<?php
   namespace helloworld;
   class sayhello {
      public static function world() {
         return 'hello world, composer!';
      }
   }
?>
we have defined a sayhello class with a world static function, which returns our hello message.
step 4 − the extension is ready. now create an empty repository at your github account and push this extension there.
inside the hello-world folder run −
- git init
 - git add
 - git commit -m “initial commit”
 - git remote add origin <your_newly_created_repository>
 - git push -u origin master
 
we have just sent our extension to the github. now, go to the https://packagist.org, sign in and click “submit” at the top menu.
you will see a page where you should enter your github repository to publish it.
step 5 − click the “check” button and your extension is published.
step 6 − go back to the basic application template. add the extension to the composer.json.
{
   "name": "yiisoft/yii2-app-basic",
   "description": "yii 2 basic project template",
   "keywords": ["yii2", "framework", "basic", "project template"],
   "homepage": "http://www.yiiframework.com/",
   "type": "project",
   "license": "bsd-3-clause",
   "support": {
      "issues": "https://github.com/yiisoft/yii2/issues?state=open",
      "forum": "http://www.yiiframework.com/forum/",
      "wiki": "http://www.yiiframework.com/wiki/",
      "irc": "irc://irc.freenode.net/yii",
      "source": "https://github.com/yiisoft/yii2"
   },
   "minimum-stability": "dev",
   "prefer-stable" : true,
   "require": {
      "php": ">=5.4.0",
      "yiisoft/yii2": ">=2.0.5",
      "yiisoft/yii2-bootstrap": "*",
      "yiisoft/yii2-swiftmailer": "*",
      "kartik-v/yii2-widget-datetimepicker": "*",
      "tutorialspoint/hello-world": "*"
   },
   "require-dev": {
      "yiisoft/yii2-codeception": "*",
      "yiisoft/yii2-debug": "*",
      "yiisoft/yii2-gii": "*",
      "yiisoft/yii2-faker": "*"
   },
   "config": {
      "process-timeout": 1800
   },
   "scripts": {
      "post-create-project-cmd": [
         "yii\\composer\\installer::postcreateproject"
      ]
   },
   "extra": {
      "yii\\composer\\installer::postcreateproject": {
         "setpermission": [
            {
               "runtime": "0777",
               "web/assets": "0777",
               "yii": "0755"
            }
         ],
         "generatecookievalidationkey": [
            "config/web.php"
         ]
      },
      "asset-installer-paths": {
         "npm-asset-library": "vendor/npm",
         "bower-asset-library": "vendor/bower"
      }
   }
}
step 7 − inside the project root folder, run the composer update to install/update all the dependencies.
step 8 − our extension should be installed. to use it, modify the about view of the actionabout method of the sitecontroller.
<?php
   /* @var $this yii\web\view */
   use yii\helpers\html;
   $this->title = 'about';
   $this->params['breadcrumbs'][] = $this->title;
   $this->registermetatag(['name' => 'keywords', 'content' => 'yii, developing, views,
      meta, tags']);
   $this->registermetatag(['name' => 'description', 'content' => 'this is the
      description of this page!'], 'description');
?>
<div class = "site-about">
   <h1><?= html::encode($this->title) ?></h1>
   <p>
      this is the about page. you may modify the following file to customize its content:
   </p>
   <h1><?= helloworld\sayhello::world();  ?></h1>
</div>
step 9 − type http://localhost:8080/index.php?r=site/about in the web browser. you will see a hello world message from our extension.