I want to manually install a magento 2 extension that only has a composer require command to install.
Is there a way to use the composer require command to download the extension dir? So it can be manually installed?
Thanks
Manually installation of the Module.
Download the extension via composer into temp dir. Open the registration.php from the dir.
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Vendorname_Modulename',
__DIR__
);
Create folder in your magento app/code/Vendorname/Modulename/
and upload files in this dir.
And run setup upgrade and deploy command.
There are severals approaches to achieve this. For the purpose of demonstration, I will assume you want to install the markshust/magento2-module-disabletwofactorauth
extension package in app/code
.
1. Download the dist (packaged version) of the extension composer package. Most of all extension packages has the dist available, you can run the following command to get the dist: composer show -a vendor/package
The command should be:
composer show -a markshust/magento2-module-disabletwofactorauth | grep "dist"
The output should look similar to this:
dist : [zip] https://api.github.com/repos/markshust/magento2-module-disabletwofactorauth/zipball/224c68d85479938f06ab2400148778575784871c 224c68d85479938f06ab2400148778575784871c
You can open the URL in the output in a browser to download the compressed extension package.
Note: This approach requires that the extension composer package is a public composer package. If the package is a paid extension, you may get the "401 Authorization Required" error code and can't download the package.
2. Download the extension composer package using composer and then copy the source code in the extension composer package to your app/code
.
Here, you have 2 approaches:
2.1. Download the extension composer package in a directory outside of your project:
Step 1: Create a new directory outside of your project
Step 2: Copy the auth.json
and composer.json
to the directory created previously.
Step 3: Download the extension composer package using composer:
composer require vendor/package
In my example, the command should looks similar to this:
composer require markshust/magento2-module-disabletwofactorauth
Step 4: Copy the source code in the extension composer package to your app/code
.
Most of all extension providers place their Magento extensions (modules) inside the extension composer package directory (Example: vendor/markshust/magento2-module-disabletwofactorauth
). However, some extension providers place their Magento extension (module) in the src directory inside the extension composer package directory (Example: vendor/sebastian/recursion-context/src
).
In this step, you will need to get the vendor and module namespace in the registration.php
file of the extension (module) to create the extension directory in app/code
directory. In my example, the registration.php file has the following content:
<?php
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'MarkShust_DisableTwoFactorAuth',
__DIR__
);
Here, the vendor is MarkShust and the extension is DisableTwoFactorAuth.
You will need to create the extension directory, which has the following format: app/code/Vendor/Extension
. In my example, the module path should be: app/code/MarkShust_DisableTwoFactorAuth
. After creating the extension directory, copy the extension source code to that directory.
2.2. Download the extension composer package in your project itself.
In this approach, follows step 3 and step 4 in the approach 1 (2.1) and then revert the change in the vendor
directory, composer.json
and composer.lock
files:
composer remove vendor/package
git checkout composer.json composer.lock