If you don’t know how to install extensions – this Magento 2 component, below you can find a detailed description of this process. The most simple and at the same time reliable solution is Magento Connect 2.0, but it will be available only after the first stable release of Magento 2. Luckily, there are several other methods.
For packages from Packagist you don’t need to add any repositories because it is the official Composer source included by default.
Once the repositories are added to your system, any Magento 2 extension can be installed with the aid of the following commandcommand
PHP
1
composer requirevendor/module
And then run
PHP
1
composer update
This will install new dependencies and required Magento 2 extensions.
Then run:
PHP
1
php bin/magento setup:upgrade
This command upgrades Magento 2 data base.
Installing Magento 2 extension by copying code
I describe this type of installation on the example of the M2 sample module. Please note that parts like M2demo/M2Extension refer to VendorName/ModuleName. Since every Magento 2 module requires a particular directory structure (<VendorName>/<ModuleName>) under<your Magento install dir>/app/code, don’t forget to replace M2demo/M2Extension with the particular data related to your Magento 2 extension.
Please note that you should be logged in as a user with the permission to write to your Magento web server docroot. Typically, it can be the root or web server user.
By performing the following actions, you will install your module:
1. Enter the following commands keeping their order:
PHP
1
2
cd<your Magento install dir>/app/code
mkdir-pM2demo/M2Extension
2. Go to the page of your module on Github (reference module in our case).
3. Find the Download Zip button and start your download.
4. Copy the downloaded file to your Magento server’s directory:<magento install dir>/app/code/m2demo/module-m2-extension.
5. Run the following commands keeping their order:
PHP
1
2
3
unzip m2extension-master.zip
mv m2extension-master/*.
rm-rf m2extension-master
6. Find your <your Magento install dir>/app/etc/config.php file and open it in a text editor.
7. Add the below command under ‘modules’ => array (
PHP
1
'M2Demo_M2Extension'=>1
8. Save the changes and close the editor.
I’ll update this Magento 2 tutorial as soon as new methods will be available. If you are looking for additional information about module installation in Magento 1.x, check our post here: How to Install Magento Extensions.