Magento 2 Composer – Errors When Installing Extensions via Composer

composercomposer-installftpmagento2mageplaza

Magento ver. 2.4.5-p1
Smartwave Porto theme

I am trying to install the 'Multiple Shipping Flat Rates' extension from Mageplaza as per a recommendation here:

Easiest way to add a second flat rate shipping method on Magento 2?

I've gone through steps ordering it and downloaded the version for Magento Community 2.4.x so I think I should be able to upload it via FTP and follow installation instructions.

I have already and will, however, install additional extensions from Amasty via composer. If that is the case, should I just try to install everything via composer rather than installing some extensions via FTP upload?

The reason I am asking is – I tried to install this extension via composer as per instructions here:

https://packagist.org/packages/mageplaza/module-multi-flat-rates

by running the following command:

composer require mageplaza/module-multi-flat-rates

But it WAS gives me this Error:

Parse error: syntax error, unexpected 'RewriterInterface' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /home/mymagentosite/public_html/vendor/laminas/laminas-dependency-plugin/src/DependencyRewriterPluginDelegator.php on line 27

I then thought maybe I first need to install the repositories (or whatever it's called), so I tried to run this command:

composer config repositories.mageplaza composer https://repo.mageplaza.com

as per the instructions on this page here:

https://www.mageplaza.com/kb/how-to-install-magento-extension-via-composer.html

but I WAS getting the same Error:

Parse error: syntax error, unexpected 'RewriterInterface' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /home/mymagentosite/public_html/vendor/laminas/laminas-dependency-plugin/src/DependencyRewriterPluginDelegator.php on line 27

Do I need to keep everything installed via composer or can I install some extensions via composer and others through an FTP upload?

The extension is here:

https://www.mageplaza.com/magento-2-multi-flat-rates-shipping/



UPDATED on April 26th:

I am no longer getting the Error above, but instead, I get the Errors below…

Regardless of what I'm trying to install, I always get the same 3 problems.

For example – trying to install the Stripe Magento extension, I try to run the following command:

composer require stripe/stripe-payments

As per this page here:

https://stripe.com/docs/connectors/adobe-commerce/install?locale=en-GB

And it gives these Errors:

The "laminas/laminas-dependency-plugin" plugin was skipped because it requires a Plugin API version (">=1.1.0 <2.3.0") that does not match your Composer installation ("2.3.0"). You may need to run composer update with the "–no-plugins" option.
Info from https://repo.packagist.org: #StandWithUkraine
./composer.json has been updated
The "laminas/laminas-dependency-plugin" plugin was skipped because it requires a Plugin API version (">=1.1.0 <2.3.0") that does not match your Composer installation ("2.3.0"). You may need to run composer update with the "–no-plugins" option.
Running composer update stripe/stripe-payments
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - magento/product-community-edition is locked to version 2.4.5-p1 and an update of this package was not requested.
    - magento/product-community-edition 2.4.5-p1 requires php ~7.4.0||~8.1.0 -> your php version (7.3.33) does not satisfy that requirement.



Problem 2
    - magento/magento-coding-standard is locked to version 27 and an update of this package was not requested.
    - magento/magento-coding-standard 27 requires php ^8.1||^8.2 -> your php version (7.3.33) does not satisfy that requirement.



Problem 3
    - magento/framework 103.0.5-p1 requires php ~7.4.0||~8.1.0 -> your php version (7.3.33) does not satisfy that requirement.
    - amasty/module-delivery-date-manager 1.0.7 requires magento/framework >=102.0.0 -> satisfiable by magento/framework[103.0.5-p1].
    - amasty/module-delivery-date-manager is locked to version 1.0.7 and an update of this package was not requested.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require stripe/stripe-payments:*" to figure out if any version is installable, or "composer require stripe/stripe-payments:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

When I try to install the mutli-flat shipping extension (mentioned above):

composer require mageplaza/module-multi-flat-rates

I get the same 3 problems come up.

What am I doing wrong and how to fix it?

My hosting already updated my composer to the newest version = 2.5.5 (stable channel).



Here is composer.json:

{
    "name": "magento/project-community-edition",
    "description": "eCommerce Platform for Growth (Community Edition)",
    "type": "project",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "config": {
        "allow-plugins": {
            "dealerdirect/phpcodesniffer-composer-installer": true,
            "laminas/laminas-dependency-plugin": true,
            "magento/*": true
        },
        "preferred-install": "dist",
        "sort-packages": true
    },
    "version": "2.4.5",
    "require": {
        "amasty/module-delivery-date-manager": "^1.0",
        "magento/composer-dependency-version-audit-plugin": "~0.1",
        "magento/composer-root-update-plugin": "~2.0",
        "magento/product-community-edition": "2.4.5-p1"
    },
    "autoload": {
        "exclude-from-classmap": [
            "**/dev/**",
            "**/update/**",
            "**/Test/**"
        ],
        "files": [
            "app/etc/NonComposerComponentRegistration.php"
        ],
        "psr-0": {
            "": [
                "app/code/",
                "generated/code/"
            ]
        },
        "psr-4": {
            "Magento\\": "app/code/Magento/",
            "Magento\\Framework\\": "lib/internal/Magento/Framework/",
            "Magento\\Setup\\": "setup/src/Magento/Setup/"
        }
    },
    "require-dev": {
        "allure-framework/allure-phpunit": "~1.5.0",
        "dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
        "friendsofphp/php-cs-fixer": "~3.4.0",
        "lusitanian/oauth": "~0.8.10",
        "magento/magento-coding-standard": "*",
        "magento/magento2-functional-testing-framework": "^3.7",
        "pdepend/pdepend": "~2.10.0",
        "phpmd/phpmd": "^2.12.0",
        "phpstan/phpstan": "^1.6.8",
        "phpunit/phpunit": "~9.5.20",
        "sebastian/phpcpd": "^6.0.3",
        "squizlabs/php_codesniffer": "~3.6.0",
        "symfony/finder": "^5.2"
    },
    "conflict": {
        "gene/bluefoot": "*"
    },
    "autoload-dev": {
        "psr-4": {
            "Magento\\PhpStan\\": "dev/tests/static/framework/Magento/PhpStan/",
            "Magento\\Sniffs\\": "dev/tests/static/framework/Magento/Sniffs/",
            "Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/",
            "Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/",
            "Magento\\Tools\\": "dev/tools/Magento/Tools/",
            "Magento\\Tools\\Sanity\\": "dev/build/publication/sanity/Magento/Tools/Sanity/"
        }
    },
    "minimum-stability": "stable",
    "prefer-stable": true,
    "repositories": {
        "amasty": {
            "type": "composer",
            "url": "https://composer.amasty.com/community/"
        },
        "0": {
            "type": "composer",
            "url": "https://repo.magento.com/"
        }
    },
    "extra": {
        "magento-force": "override"
    }
}

The composer.lock has 25676 rows so I posted it to Codeshare:

https://codeshare.io/bv0wgM



I am now trying to go through the steps as outlined by Raul Sanchez:

  1. I deleted the composer.lock file in Magento root.
  2. I tried installing composer by putting in the following command into Putty on Magento root:

composer install

It gave these Errors:

The "laminas/laminas-dependency-plugin" plugin was skipped because it requires a Plugin API version (">=1.1.0 <2.3.0") that does not match your Composer install ation ("2.3.0"). You may need to run composer update with the "–no-plugins" opt ion.
No composer.lock file present. Updating dependencies to latest instead of instal ling from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires magento/product-community-edition 2.4.5-p1 -> satisfiable by magento/product-community-edition[2.4.5-p1].
    - magento/product-community-edition 2.4.5-p1 requires php ~7.4.0||~8.1.0 -> your php version (7.3.33) does not satisfy that requirement.



Problem 2
    - composer/composer[1.6.0, ..., 1.9.3] require symfony/finder ^2.7 || ^3.0 || ^4.0 -> found symfony/finder[v2.7.0, ..., v2.8.52, v3.0.0, ..., v3.4.47, v4.0.0, ..., v4.4.44] but it conflicts with your root composer.json require (^5.2).
    - magento/framework[103.0.4, ..., 103.0.5-p2] require php ~7.4.0||~8.1.0 -> your php version (7.3.33) does not satisfy that requirement.
    - magento/framework 103.0.6 requires php ~8.1.0||~8.2.0 -> your php version (7.3.33) does not satisfy that requirement.
    - magento/framework[102.0.0, ..., 102.0.2-p2] require php ~7.1.3||~7.2.0 -> your php version (7.3.33) does not satisfy that requirement.
    - Root composer.json requires friendsofphp/php-cs-fixer ~3.4.0 -> satisfiable by friendsofphp/php-cs-fixer[v3.4.0].
    - Conclusion: don't install amasty/module-delivery-date-manager 1.0.8 (conflict analysis result)
    - magento/framework[102.0.5, ..., 102.0.6-p1, 103.0.0, ..., 103.0.1-p1] require composer/composer ^1.9 -> satisfiable by composer/composer[1.9.0, ..., 1.10.26].
    - magento/framework[102.0.3, ..., 102.0.4-p2] require composer/composer ^1.6 -> satisfiable by composer/composer[1.6.0, ..., 1.10.26].
    - composer/composer[1.10.0, ..., 1.10.26] require composer/semver ^1.0 -> satisfiable by composer/semver[1.0.0, ..., 1.7.2].
    - You can only install one version of a package, so only one of these can be installed: composer/semver[1.0.0, ..., 1.7.2, 3.0.0, ..., 3.3.2].
    - friendsofphp/php-cs-fixer v3.4.0 requires composer/semver ^3.2 -> satisfiable by composer/semver[3.2.0, ..., 3.3.2].
    - Root composer.json requires magento/magento2-functional-testing-framework ^3.7 -> satisfiable by magento/magento2-functional-testing-framework[3.7.0, ..., 3.12.0].
    - amasty/module-delivery-date-manager[1.0.0, ..., 1.0.8] require magento/framework >=102.0.0 -> satisfiable by magento/framework[102.0.0, ..., 102.0.7-p3, 103.0.0, ..., 103.0.6].
    - magento/framework[102.0.7, ..., 102.0.7-p3, 103.0.2, ..., 103.0.3-p3] require monolog/monolog ^1.17 -> satisfiable by monolog/monolog[1.17.0, ..., 1.27.1].
    - Conclusion: don't install monolog/monolog 1.27.1 (conflict analysis result)
    - Root composer.json requires amasty/module-delivery-date-manager ^1.0 -> satisfiable by amasty/module-delivery-date-manager[1.0.0, ..., 1.0.8].
  1. When I run this:

    composer -v

It shows this:

Composer version 2.5.5 2023-03-21 11:50:05

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display help for the given command. When no command is given display help for the list command
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi|--no-ansi           Force (or disable --no-ansi) ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
      --no-scripts               Skips the execution of all scripts defined in composer.json file.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
      --no-cache                 Prevent use of the cache
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  about                Shows a short information about Composer
  archive              Creates an archive of this composer package
  audit                Checks for security vulnerability advisories for installed packages
  browse               [home] Opens the package's repository URL or homepage in your browser
  bump                 Increases the lower limit of your composer.json requirements to the currently installed versions
  check-platform-reqs  Check that platform requirements are satisfied
  clear-cache          [clearcache|cc] Clears composer's internal package cache
  completion           Dump the shell completion script
  config               Sets config options
  create-project       Creates new project from a package into given directory
  depends              [why] Shows which packages cause the given package to be installed
  diagnose             Diagnoses the system to identify common errors
  dump-autoload        [dumpautoload] Dumps the autoloader
  exec                 Executes a vendored binary/script
  fund                 Discover how to help fund the maintenance of your dependencies
  global               Allows running commands in the global composer dir ($COMPOSER_HOME)
  help                 Display help for a command
  init                 Creates a basic composer.json file in current directory
  install              [i] Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json
  licenses             Shows information about licenses of dependencies
  list                 List commands
  outdated             Shows a list of installed packages that have updates available, including their latest version
  prohibits            [why-not] Shows which packages prevent the given package from being installed
  reinstall            Uninstalls and reinstalls the given package names
  remove               Removes a package from the require or require-dev
  require              [r] Adds required packages to your composer.json and installs them For magento/product-community-edition, magento/product-enterprise-edition, or magento/magento-cloud-metapackage updates, use require-commerce.
  require-commerce     [r] Adds required packages to your composer.json and installs them If a magento/product-community-edition, magento/product-enterprise-edition, or magento/magento-cloud-metapackage change is required, also makes any associated composer.json changes.
  run-script           [run] Runs the scripts defined in composer.json
  search               Searches for packages
  self-update          [selfupdate] Updates composer.phar to the latest version
  show                 [info] Shows information about packages
  status               Shows a list of locally modified packages
  suggests             Shows package suggestions
  update               [u|upgrade] Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file
  validate             Validates a composer.json and composer.lock

When I try to run:

composer require mageplaza/module-multi-flat-rates

It gives these Errors:

Problem 1
    - Root composer.json requires magento/product-community-edition 2.4.5-p1 -> satisfiable by magento/product-community-edition[2.4.5-p1].
    - magento/product-community-edition 2.4.5-p1 requires php ~7.4.0||~8.1.0 -> your php version (7.3.33) does not satisfy that requirement.



Problem 2
    - composer/composer[1.6.0, ..., 1.9.3] require symfony/finder ^2.7 || ^3.0 || ^4.0 -> found symfony/finder[v2.7.0, ..., v2.8.52, v3.0.0, ..., v3.4.47, v4.0.0, ..., v4.4.44] but it conflicts with your root composer.json require (^5.2).
    - magento/framework[103.0.4, ..., 103.0.5-p2] require php ~7.4.0||~8.1.0 -> your php version (7.3.33) does not satisfy that requirement.
    - magento/framework 103.0.6 requires php ~8.1.0||~8.2.0 -> your php version (7.3.33) does not satisfy that requirement.
    - magento/framework[102.0.0, ..., 102.0.2-p2] require php ~7.1.3||~7.2.0 -> your php version (7.3.33) does not satisfy that requirement.
    - Root composer.json requires friendsofphp/php-cs-fixer ~3.4.0 -> satisfiable by friendsofphp/php-cs-fixer[v3.4.0].
    - Conclusion: don't install amasty/module-delivery-date-manager 1.0.8 (conflict analysis result)
    - magento/framework[102.0.5, ..., 102.0.6-p1, 103.0.0, ..., 103.0.1-p1] require composer/composer ^1.9 -> satisfiable by composer/composer[1.9.0, ..., 1.10.26].
    - magento/framework[102.0.3, ..., 102.0.4-p2] require composer/composer ^1.6 -> satisfiable by composer/composer[1.6.0, ..., 1.10.26].
    - composer/composer[1.10.0, ..., 1.10.26] require composer/semver ^1.0 -> satisfiable by composer/semver[1.0.0, ..., 1.7.2].
    - You can only install one version of a package, so only one of these can be installed: composer/semver[1.0.0, ..., 1.7.2, 3.0.0, ..., 3.3.2].
    - friendsofphp/php-cs-fixer v3.4.0 requires composer/semver ^3.2 -> satisfiable by composer/semver[3.2.0, ..., 3.3.2].
    - Root composer.json requires magento/magento2-functional-testing-framework ^3.7 -> satisfiable by magento/magento2-functional-testing-framework[3.7.0, ..., 3.12.0].
    - amasty/module-delivery-date-manager[1.0.0, ..., 1.0.8] require magento/framework >=102.0.0 -> satisfiable by magento/framework[102.0.0, ..., 102.0.7-p3, 103.0.0, ..., 103.0.6].
    - magento/framework[102.0.7, ..., 102.0.7-p3, 103.0.2, ..., 103.0.3-p3] require monolog/monolog ^1.17 -> satisfiable by monolog/monolog[1.17.0, ..., 1.27.1].
    - Conclusion: don't install monolog/monolog 1.27.1 (conflict analysis result)
    - Root composer.json requires amasty/module-delivery-date-manager ^1.0 -> satisfiable by amasty/module-delivery-date-manager[1.0.0, ..., 1.0.8].

You can also try re-running composer require with an explicit version constraint, e.g. "composer require mageplaza/module-multi-flat-rates:*" to figure out if any version is installable, or "composer require mageplaza/module-multi-flat-rates:^2.1" if you know which you need.

Installation failed, reverting ./composer.json to its original content.

I guess I need to do #3. but I am not sure which exact lines to remove from my composer.json? Should I remove all of the following?

],
    "config": {
        "allow-plugins": {
            "dealerdirect/phpcodesniffer-composer-installer": true,
            "laminas/laminas-dependency-plugin": true,
            "magento/*": true
        },

Also – there is no composer.lock file in Magento root anymore (it didn't recreated itself) – is that a problem?



UPDATE:

I installed PHP 8.1 now and ran the following:

composer install --no-cache

It shows the following:

The "laminas/laminas-dependency-plugin" plugin was skipped because it requires a Plugin API version (">=1.1.0 <2.3.0") that does not match your Composer installation ("2.3.0"). You may need to run composer update with the "--no-plugins" option.
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Your requirements could not be resolved to an installable set of packages.



Problem 1
    - php-amqplib/php-amqplib v3.2.0 requires ext-sockets * -> it is missing from your system. Install or enable PHP's sockets extension.
    - magento/product-community-edition 2.4.5-p1 requires php-amqplib/php-amqplib ~3.2.0 -> satisfiable by php-amqplib/php-amqplib[v3.2.0].
    - Root composer.json requires magento/product-community-edition 2.4.5-p1 -> satisfiable by magento/product-community-edition[2.4.5-p1].

To enable extensions, verify that they are enabled in your .ini files:
    - /opt/cpanel/ea-php81/root/etc/php.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-bcmath.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-bz2.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-calendar.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-ctype.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-curl.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-dba.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-dom.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-enchant.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-exif.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-fileinfo.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-ftp.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-gd.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-gettext.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-gmp.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-iconv.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-intl.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-mbstring.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-mysqlnd.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-pdo.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-phar.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-posix.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-pspell.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-simplexml.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-soap.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-sodium.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-sqlite3.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-tidy.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-tokenizer.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-xml.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-xmlwriter.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-xsl.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/20-zip.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/30-mysqli.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/30-pdo_mysql.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/30-pdo_sqlite.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/30-xmlreader.ini
    - /opt/cpanel/ea-php81/root/etc/php.d/zzzzzzz-pecl.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-sockets` to temporarily ignore these required extensions.

FINAL UPDATE:
Deleting composer.lock & running composer install fixed the problem.
Thank you all for your help!

Best Answer

  1. Please to update your PHP version, as per magento 2.4.5-p1 version requirement is PHP 7.4-8.1 https://experienceleague.adobe.com/docs/commerce-operations/installation-guide/system-requirements.html
  2. Once you updated the PHP version to the recommended & required one, try to run composer install --no-cache. why no cache? just want to make sure the process wont disturb by your composer cache and you will get the same result even if you run it on a different computer.
  3. then try to run composer require the amasty/mageplaza

UPDATE (post PHP8.1 switching) 2023-04-28:

  1. based on your update, please to install all required PHP extensions as what explained here https://experienceleague.adobe.com/docs/commerce-operations/installation-guide/prerequisites/php-settings.html?lang=en
  2. (optional) if first step does it's job and you have no ext error, but if you still face the same issue after you switched to PHP 8.1, try to delete the laminas plugins.