How to install external libraries to magento2 without using composer?

How to install external libraries to magento2 without using composer?

August 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to install external libraries to magento2 without using composer?

Managing External Libraries in Magento2: A Composer-Free Approach

As an experienced developer, I often encounter situations where I need to integrate external PHP libraries into my e-commerce projects but face constraints such as limited server memory or the need for a more direct control over the installation process.

In this post, we’ll explore how to add the popular PHPMailer library to your Magento2 website without relying on Composer, offering an alternative approach that provides more flexibility and control over the integration process.

Understanding the Challenge

The most common method of integrating an external library in Magento2 is through Composer. However, this approach may not always be feasible due to server limitations or specific project requirements.

For instance, when attempting to install PHPMailer using Composer on a server with limited memory allocation, you might encounter the infamous “out of memory” error:

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 1073741824 bytes)

This typically happens when your server doesn’t have sufficient resources to handle the Composer installation process.

A Composer-Free Alternative

If you find yourself in this situation, there is a viable alternative approach that allows you to manually integrate the PHPMailer library into your Magento2 project without using Composer:

  1. Download the Library Manually

  2. Copy Files to Magento2 Root

    • Navigate to your local Magento2 installation directory
    • Create a new folder named vendor inside the Magento2 root directory (if it doesn’t exist already)
    cd /path/to/magento2/root
    mkdir vendor
    
  3. Upload the PHPMailer Folder

    • Upload the PHPMailer folder you extracted earlier into the newly created vendor directory
    upload /path/to/phpmailer-6.5.0/PHPMailer vendor/
    
  4. Update the Autoload File

    • Open the composer.json file located in your Magento2 root directory
    • Add a new line at the end of the “autoload” section to include the PHPMailer namespace
    "autoload": {
        "psr-4": {
            "PHPMailer\\PHPMailer\\": "vendor/phpmailer/phpmailer/src"
        }
    },
    
  5. Create an Autoloader File

    • Create a new PHP file named autoload.php in the Magento2 root directory
    • Add the following content to this new file:
    <?php
    require 'vendor/autoload.php';
    

This manual approach allows you to integrate external libraries without relying on Composer, providing more direct control over the installation process and memory utilization.

Conclusion

While Composer is the recommended way of managing dependencies in Magento2, understanding how to manually integrate external libraries can be invaluable when facing server limitations or specific project requirements.

By following this alternative approach, you can successfully add PHPMailer or any other library to your project without consuming precious server resources during the installation process.

Remember that maintaining a clean and organized codebase is essential for the long-term success of your e-commerce projects. Always strive for best practices and keep an eye on Laravel Company’s blog for more insights into Magento2 development: https://laravelcompany.com/blog/

Magento 2 Deployment Email Errors

Our network