Yii 2 Extensions Without Composer

Ok, i am not a big fan of using tools like composer, far preferring to install things myself so that I know where everything is.

So, I have tried to install an extension, residing where I want it to reside. I have adjusted namespaces accordingly, but Yii still cannot find the extension.

What gives?

You should add to vendor/yiisoft/extensions.php

But better to learn Composer.

Though, I do not understand why you should not use composer … but still if you are so keen in doing stuff manually:


[*]Copy extension files correctly to the vendor folder and add the extension configuration to vendor\yiisoft\extensions.php as samdark mentioned

[*]But in addition and before that read the composer.json for each extension you want to install. You will find the list of prerequisite packages in the require section. You need to ensure all these pre-requisite packages are downloaded manually and install them like in Step 1. After doing all this, if you feel its done - I would suggest wait… not yet. Go to step 3 to revalidate.

[*]For each package you downloaded in step 2 - check its individual composer.json and find if that package depends on something else in the require section. You need to hierarchically repeat this for all pre-requisites like in step 1 and step 2.


Hope that satisfies your curiosity to do manually … remember you must technically scan through the package dependency hierarchy always - everytime you install or upgrade a package .

Or … if you are not that curious and want to get stuff done automatically and faster… just add the package spec to the require section of your app’s composer.json and type php composer.phar update in your shell prompt.

Yii2 is the same. You can put anything anywhere. Add Yii::setAlias('@libs', '/anywhere/src/libs') and Yii will autoload classes with namespace = libs/ from that dir and subdirs. Also you can get the path itself via Yii::getAlias().

Thanks for your half answer. I’m sure I’ll eventually figure it out from here.

The thing with Yii2 is that NAMESPACES are in. So you can keep any stuff anywhere in any folder and access it through namespaces. So if you want to mimic Yii 1.1 for example and create your own module … you can create a directory: approot/modules/pkg1.

Then you can simply access the module classes anywhere like this:

use app\modules\pkg1\ModuleClass;

OR you can create approot/extensions/Extension1.php

and access it anywhere like this

use app\extensions\Extension1;

You can also use any other folder other than approot and set an alias as samdark mentioned. Hope that clarifies.

If you are installing THIRD PARTY EXTENSIONS — you are recommended to use composer.

I like Yii2 embracing a package dependency manager like composer and making app and extension management so easy. Congrats dev team!

This is been so successful with frameworks like Symfony - so a great step forward and definitely IMO should improve further with usage and learning.

I ain’t sure why some people are so resistant to change and accept new things. People like mr. backslider only crib about adopting changes like using composer, rather than understanding how it works or why so many experts have voted yes for it. If there are genuine suggestions, share them - create a github issue or PR, contribute to improve, rather than disrespecting and accusing the core design.

Clearly mr. backslider, you do not seem to know what composer is and how it impacts your other packages - as seen by your ignorant comment and silly outburst on yii core files getting overwritten, when updating an extension. If you do not know about a topic, understand and read documentation, before commenting on other work.

On composer usage, there surely must be some reason, why popular framework development experts (e.g. Symfony, Zend, Laravel, Yii2) use composer as a dependency manager in their frameworks?

We definitely need major extension creators (like @Kartik) to help this community grow - rather than having people like mr. backslider who show a personal attitude or grudge, without adding any value.

The simplest A simple way to manage your own extension might be storing it under "vendor/backslider" directory. It will make things far much easier and simpler. You can make that extension private if you want.

Try a little bit of Composer, and you’ll like it. :)

And Composer is a MUST for a yii2 developer, IMO.

I do understand how it works.

I think it’s a great idea, however when those writing extensions do not understand or respect what a “beta” release of the framework is and the fact that their installation through Composer should not include overwriting core files then it’s not so good, especially when it breaks something as essential as Yii bootstrap.

If I wish to update Yii, then that should be my choice, not somebody else’s. If the extension cannot run on the current release, as is, then it should be very clearly stated.

I DO not think you still understand how it works. That’s the only reason you are facing a problem with managing extensions using composer and MOST OTHERS are not.

If you know how composer works you would know the following:


[*] each extension typically depends on a set of packages - you should find which packages and what versions its dependent from each EXTENSION’s composer.json file and documentation and then take a decision on installing. ITS FOOLISH to be accusing the extension creators, since you have taken a decision to install based on dependency.

[*]IT IS EXPECTED BEHAVIOR FOR COMPOSER to UPDATE ALL DEPENDENT PACKAGES from their SOURCES. NOTE: EXTENSIONS DIRECTLY DO NOT CONTAIN FILES THAT OVERWRITE OTHER CORE PACKAGES. IT IS TIME YOU LEARNT THIS. COMPOSER decides based on the package dependency settings what to download and what to update (from each dependent package source version and location) and in what order.

[*] Unless you have tampered and edited package code in vendors directory yourself, updating packages via composer normally do not cause issues to your application, rather it cleans up bugs and gives you new features.

[*]LASTLY, MOST IMPORTANT, You MUST ALSO LEARN ABOUT USING composer.lock AND HOW YOU CAN LOCK SPECIFIC PACKAGES to SPECIFIC VERSIONS to control COMPOSER OVERWRITING packages. I AM NOT SURE YOU KNOW THIS - because you have been going all around crying, some extension overwrote a yii bootstrap version. Instead of accepting, its your problem, you went around accusing all others except you.


There are other ways as well in how you control COMPOSER. But its your choice in the end how you understand using this. Its your choice if you do not want to use composer, and do things your way.

HOWEVER, what is NOT ACCEPTABLE is instead of choosing to learn yourself, you accuse and bad mouth, the Yii2 creators and other good contributors to the Yii2 community.

We rather want them and want their continued interest in contributing to the community. I personally like many others, want them to continue supporting us and not get dissuaded because some guy does not know to USE things properly.

Let us use Yii2 the way it is designed to be! We all report issues on the project page and are comfortable with the way the Yii2 DEV team is handling it.

I understand perfectly how it works.

Clearly you do not understand the core principles of source control.

We are at a "beta" release. An extension should have no dependencies in relation to the core framework that are outside of that scope. That is, zero core files should be overwritten. This fact is proven by the result: a broken Yii bootstrap. I did absolutely nothing out of the ordinary.

I am perfectly happy to use composer for official Yii extensions, however will in no wise use it again for outside extensions, because developers clearly do not understand or respect that you should not mess with the core, particularly once it has been released as beta.

Now, you want to lecture me on a whole rigmarole of things I should do before using composer. That would take a significant amount of time. To install an extension manually would take me about three minutes. If it won’t run on a standard release then it is simple enough to again remove.

Wrong statement. Before you comment, you need to know how many frameworks and projects run along with composer and each framework has its own versions, releases, and extensions? Do you mean to say they do not enable source control for developers? Developers need to learn to work with different technologies, in achieving their requirements.

Its just like a plain PHP developer coming to Yii framework and – saying why do I need to configure my db component in Yii Config file and configure a Yii Active Record - rather than directly writing my own db connection and PDO query from scratch.

Understand the Yii2 framework design and what it stipulates in its vendor extensions? If you do not care what the Yii2 framework design stipulates, why do you use the framework?

First begin by understanding the issue: Extensions should not initiate the overwrite of core framework files when we are in beta, unless it is made clear that this will happen (without going through the rigmarole which you suggest).

Now, you are perfectly free to disagree with that, but…

And that’s why you need to read and understand again… an extension never maintains the core framework files or overwrites core framework files. So saying this itself is WRONG.

Every package update is done by composer based on package dependency. And you would clearly know for every extension, what its package dependencies and dependent versions are (read the composer.json). So it is you in the end who need to decide, whether those dependency versions are ok for your app, and you control the installation, overwriting rules, based on what you need - rather than accusing others. But by no means say that because you goofed up, hence everyone should stop using Yii2 composer or any extension.

Its exactly same when you do this manually as well. You decide which version of each package when you copy paste manually an extension and its dependencies.

I think by "extensions should not initiate the overwrite of core framework files" he actually means "updating or installing extensions should not trigger update of the framework".

If an extension depends on ‘yiisoft/yii2: *’ - some developers may want ‘yiisoft/yii2’ to be locked to the beta version while others may want this to auto update to the latest dev version.

The control for this lies with the developer to choose what they want for their app. They need to read the extension dependency, setup and lock what they need, figure out if it is ok for their environment or its a break for the extension, and then choose the method to run the composer install or update — which in turn defines how framework files are auto updated by composer.


I have been using a lot of software over many many years and have never encountered such a thing. For example, I use Firefox daily as it has some great extensions for developers. My current version is 29. Now, whenever I install an extension it would never ever install anything for Firefox 30-dev and force an upgrade of Firefox to dev. Not ever.

Likewise, whenever I have encountered a package which was "dev" or had "dev" dependencies, then that has always been made abundantly clear from the outset.

Which comes back to the question: Why then bother? Since it would take me far less time to manually install and see whether it works or not. Do you not think it far better for the extension developer to make this clear?

Because the framework is itself built in a way, where it is using composer as a dependency tool and even the core framework in some cases depends on a hierarchy of third party dependent packages - all parsed by composer.

So even if you skip installing extensions - you may have the same third party package version which core framework installs that can cause a conflict to your app (if you were dependent on another version of the same third party package).

Very much debatable - as to which takes less time and which is better. While I will say, composer takes me much lesser time with much less errors - I am sure, you will probably argue the other way (as seen so far with your huge resistance to change). Irrespective of any method - responsibility lies with you as a developer for checking package version dependency and conflict for your app. An extension creator will not know what versions you have in your app - the only thing they will have is the set of package versions needed for their extension to run fine.

Since yii2 stipulates the composer method to install extensions - you do not need elaborate documentation to understand about the extension installation or the package dependency - you just read the composer.json file in the extension root folder, and then decide if that’s ok for your app - that’s all.