Using Composer


Can anybody here explain me briefly how to use Composer having multiple Yii projects on a computer?

For instance:

Let’s say I have one Yii ‘Advanced’ project installed with:

php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced /var/www/yii_adv

and I have another ‘Basic’ project installed with:

php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic /var/www/yii_bas

Now the question is:

How to add certain extension (using Composer) specifically to let’s say ‘Advanced’ project and leave ‘Basic’ one intact?

Thanks ahead for your feedback!


I’m still not very used to composer :blink: but IMHO the projects are already independently with your described folder structure.

If you want to use a extension just add it to the composer.json file in your desired project (e.g. yii_adv).

Then do

user@host:/var/www/yii_adv/ # composer update

inside yii_adv folder.

New extension should now be available in yii_adv project.

Thank you!

Anyway - this is a bit confusing with this way with editing JSONs.

I would rather has a Composer command like "add2project" where I provide a project name and required extension and it adds necessary JSON entries itself and then updates the project…

Thanks anyway!

Hey Ziggi,

Here are some examples of what you were looking for:

php composer.phar require yiisoft/yii2 "*"


php composer.phar require "michelf/php-markdown:>=1.3" "ezyang/htmlpurifier:>4.5.0"

if you have composer installed globally you can do:

composer require "extension" "version_of_extension"

also check the guide at:

Yii2 composer guide

Hi marianzburlea

Unfortunately - it seems I musunderstand how Composer knows what project I mean while executing "require" :frowning: