0

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

2 Answers 2

0

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.

2
  • 1. Following your composer show command I created the below command. composer show -a sparsh/magento-2-faq-extension | grep "dist" 2. I got the below output repo.magento.com/archives/sparsh/magento-2-faq-extension/… When opening the URL in browser in step 2 it says “You haven't provided your Magento authentication keys” How would I add the auth key to the repo output URL to allow me to download the package to my local drive?
    – Alaldin
    Commented Aug 28, 2023 at 8:52
  • @Alaldin In this case, you can't use the first (1) approach, use the second (2) approach instead. By the way, since your comment is in response to my answer, please make sure to add it in my answer, rather than in this answer. Otherwise, I won't receive a notification.
    – Tu Van
    Commented Aug 30, 2023 at 6:37
0

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:

  • Download the extension composer package in a directory outside of your project.
  • Download the extension composer package in your project itself.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.