Wait! Don't use app/code! - Installing Adobe commerce modules the right way

baw-187
Wait! Don't use app/code! - Installing Adobe commerce modules the right way

Adobe Commerce Modules

Adobe Commerce stands at the forefront of e-commerce solutions, offering unparalleled flexibility and customization through the use of modules. These modules (sometimes called extensions) are pivotal in tailoring the platform to meet diverse business needs, from enhancing user experience to integrating third-party services. However, the benefits derived from these modules are maximized only when they are installed following best practices. This guide goes over crucial insights into a cohesive strategy for module installation, prioritizing the stability, security, and upgradeability of your Adobe Commerce platform.

Manual Installation 

Choosing to manually install a Adobe Commerce module by placing files into the app/code directory might initially appear easy. Copy the module files, enable it, and you’re done. However, this approach often leads to more significant challenges:

Upgrade and Maintenance Complexities

Manually adding modules into app/code makes tracking updates and performing maintenance a cumbersome, error-prone task. Without the automated version control provided by Composer, ensuring your modules are current becomes a manual chore fraught with potential for oversight.

Compatibility Concerns

Installing in app/code means missing out on its crucial compatibility checks. This oversight can result in conflicts with Adobe Commerce's core or other modules, jeopardizing your site's stability and overall functionality.

Deviation from Adobe Commerce Best Practices

Installing modules manually goes against Adobe Commerce's best practices. This can lead to difficulties obtaining support or troubleshooting, as your setup deviates from the standard configurations.

Increased Security Risks

Directly managing module files, particularly from unverified sources, heightens the risk of introducing security vulnerabilities to your site. Composer addresses these concerns by sourcing packages from reputable, trusted repositories.

 

Appropriate Use of Manual Installation

Manual installation should be reserved for modules developed in-house or by your trusted e-commerce agency, not for third-party code. This ensures that you maintain control over the code quality and security standards.

So, what's the alternative if manual placement in app/code is it not recommended for third-party modules? Enter Composer, Adobe Commerce preferred tool for module management. Composer streamlines installations, updates, and dependency management, aligning your site with Adobe Commerce's best practices and ensuring a more secure, maintainable, and upgrade-friendly environment.

Composer

The official composer documentation can be found on their website https://getcomposer.org/

Before we get into why we should be using Composer, we will go over what Composer is and why we would want to use it.

Composer is a PHP dependency manager. A tool that ensures all the code we want to run on the site is installed at the correct version and is downloaded from a trusted source. Imagine Composer as your project's building contractor, tasked with constructing a custom home. You provide the dream design, and Composer lays the foundation, ensuring every brick (PHP package) fits perfectly and is sourced from trusted suppliers. Like a skilled contractor who selects the right materials for durability and compatibility, Composer meticulously gathers all necessary components, ensuring they meet your project's specifications and work harmoniously together. This process guarantees your custom home is built solidly and efficiently, matching your vision with precision.

How to Use Composer:

  1. Find the Module: Obtain the Composer package name and the version of the module you want to install. This information is typically provided by the module developer or can be found on the Adobe Commerce Marketplace.  

  2. Prepare Your Environment: Ensure your Adobe Commerce environment is ready for installation. This means having Composer installed and your Adobe Commerce application already set up.

  3. Command Line Installation: 

  • Open your terminal or command prompt.
  • Navigate to the root directory of your Adobe Commerce installation
  • Execute the following command, replacing <vendor>/<module-name> with the module's Composer name and <version> with the desired version:
    composer  require <vendor>/<module-name>:<version>
  • Composer will download the module and its dependencies.
  1. Enable the Module:

  • After the installation is complete, you need to enable the module in Adobe Commerce. Still in the root directory of your Adobe Commerce installation, execute:
    bin/magento setup:upgrade
  • This command registers the module with Adobe Commerce, updates the database schema, and prepares the module for use.
  1. Clear Cache and Compile (if necessary):

  • Clear the cache to ensure Adobe Commerce recognizes the new module: 
    bin/magento cache:clean
  • If you're in production mode or require it, also run the compile command to generate code and optimize for performance:
    bin/magento setup:di:compile

Artifacts - What if the code doesn't have a Composer repo?

Sometimes, you'll need to install a module that doesn't have a Composer repo.  Maybe you're working with a vendor that emails you a copy of their module and asks you to install it.  In those cases, you can still harness the power of the Composer! Installing a module in this way is commonly referred to as an 'artifact'.  To install a module as an artifact we need to perform a bit of setup. 

  1. Prepare Your Artifact:

  • Ensure your module is packaged correctly, typically in a .zip format.
  • Place the .zip package in a dedicated directory, for example, path/to/artifacts.
  1. Configure Composer:

  • Open your Adobe Commerce project's composer.json file.
  • Add an artifact repository pointing to the directory containing your module package. For example:
    "repositories": [ {"type":"artifact","url":"path/to/artifacts" } ]
  1. Install the Module:

  • From the command line, navigate to your Adobe Commerce root directory.
  • Run Composer require to install the module. Since the module isn't in a standard repository, you must reference it by its name and version directly as specified in its composer.json. If the module doesn't specify a version, you can use * it as the version. For example:
    composer  require vendor/module-name:*
  • Composer will look in your artifacts directory for the module and install it.
  1. Enable and Set Up the Module:

  • Once the module is installed, enable it by running:
    bin/magento module:enable VendorName_ModuleName
  • Update the database schema and data with:
    bin/magento setup:upgrade
  1. Finalize Installation:

  • Clean the cache to ensure Adobe Commerce recognizes the new module:
    bin/magento cache:clean
  • If necessary, deploy static content and recompile:
    bin/magento setup:static-content:deploy && bin/magento setup:di:compile

Best Practices Recap

  • Prioritize Composer: For its comprehensive approach to dependency management, ease of updates, and direct integration with Adobe Marketplace, Composer should be your first choice for installing Adobe Commerce modules.
  • Reserve app/code for Custom Development: The manual installation of third-party modules into app/code is advised against due to potential complications in upgrading and managing dependencies.
  • Stay Informed and Updated: Regularly check for module updates and maintain awareness of new best practices in Adobe Commerce module management.

Need help?

If you've made it to this point, congratulations! You're now more knowledgeable about the inner workings of Adobe Commerce and have a better understanding of one of Adobe Commerce's most critical best practices. If you're curious to learn more or need assistance, don't hesitate to reach out. Our team at Binary Anvil is here to help! From module installs to complex ERP integrations, we've got the skills to ensure your Adobe Commerce store runs like a well-oiled machine. Contact us today to discover how we can elevate your store's performance and simplify your e-commerce journey. Let's transform the complicated into the manageable, together!

Joshua Fedoryszyn
April 26, 2024

linkedin

Comments

Add new comment

14 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Lead Contact

SUBSCRIBE TO OUR NEWSLETTER

Signup to our newsletter to get the latest news, updates and amazing offers delivered directly in your inbox.