magento2: Magento version UNKNOWN

Preconditions

  1. Starting with Magento 2.2.5 installed via composer on CentOS7 (centos-release-7-6.1810.2.el7.centos.x86_64) on CentOS 7 & nginx version: nginx/1.12.2, php 7.0. My original Magento 2.2.5 composer.json is here. Config and data were migrated from a pre-existing Magento 1.9 store.
  2. Upgraded php to 7.1.28 and Magento 2.3.1. My final composer.json is here.

Steps to reproduce

  1. I (believe I have) upgraded to 2.3.1 using the script method. I hit issues along the way (documented here) but eventually I have managed to run the pre_composer_update_2.3.php script. To do this I had to amend the composer.json with "name": "magento/product-community-edition", "version": "2.3.1", Then I had to repeatedly run composer update and progressively run remove all the pre-existing dependancies from composer.json that conflicted with those for the new upgrade.
  2. Probably not related, but, I had not installed mcrypt at this stage since it was not mentioned here, however after enabling compilation I got exception main.CRITICAL: Notice: Use of undefined constant MCRYPT_BLOWFISH - assumed 'MCRYPT_BLOWFISH' So, I installed it and after flushing caches and recompiling, both front and backends are working.

Expected result

  1. Expect to be able to retrieve a Magento version by any of these methods: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/versioning/check-version.html

Actual result

  1. I log into the admin area however at the bottom of the page I see “Magento ver. UNKNOWN”.
  2. Running: bin/magento --version gives: “Magento CLI”
  3. I see nothing in the headers when requesting http://<magento2-store>/magento_version
  4. There is no “magento/product-community-edition” mentioned in my composer.lock

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

So I dug in a bit more, since I was curious 😃

It looks like when you install Magento2 using composer, it searches the version in a package what Magento calls a “system package”, that is determined if the name of that package matches the regex magento/product-* and then that version is used. (this regex is wrong in my opinion, it should probably be: magento/product-.+, but that’s beside the question here). If it can’t find such a package, it assumes Magento is installed by cloning the git repo, and it will search for the version in the root composer.json file. But it looks like the version is no longer provided in the composer.json file in the git repo, this got removed in: https://github.com/magento/magento2/commit/95bfd2c790f9f84c81f0f25807623d136555f7ea#diff-b5d0ee8c97c7abd7e3fa29b9a27d1780R4 (it is still there in tagged versions however, then it gets put back in place luckily). So how does composer then figure out a version if it isn’t specified in the composer.json file? It looks like it takes the current branch in git which is checked out, this happens in Composer’s VersionGuesser class.

So summary @benhtn:

  • Check if you have one or multiple packages in your composer.json file which name starts with: magento/product. If that’s the case, the version of that one should be used.
  • If that isn’t the case, then there is probably a problem with your composer.json file (see below for an example file).
  • But it might also be caused by an outdated version of composer/composer being installed in your Magento shop (run composer show | grep composer/composer to see which one is installed, latest available at the time of writing is 1.8.5 for Magento 2.3.1), or even an outdated git version (I’m using 2.21.0).

Hope this helps somehow 😃

As a reference, here is the root composer.json when setting up a new Magento 2.3.1 installation:

{
    "name": "magento/project-community-edition",
    "description": "eCommerce Platform for Growth (Community Edition)",
    "type": "project",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "config": {
        "preferred-install": "dist",
        "sort-packages": true
    },
    "require": {
        "magento/product-community-edition": "2.3.1"
    },
    "require-dev": {
        "friendsofphp/php-cs-fixer": "~2.13.0",
        "lusitanian/oauth": "~0.8.10",
        "magento/magento2-functional-testing-framework": "~2.3.13",
        "pdepend/pdepend": "2.5.2",
        "phpmd/phpmd": "@stable",
        "phpunit/phpunit": "~6.5.0",
        "sebastian/phpcpd": "~3.0.0",
        "squizlabs/php_codesniffer": "3.3.1",
        "allure-framework/allure-phpunit": "~1.2.0"
    },
    "conflict": {
        "gene/bluefoot": "*"
    },
    "autoload": {
        "psr-4": {
            "Magento\\Framework\\": "lib/internal/Magento/Framework/",
            "Magento\\Setup\\": "setup/src/Magento/Setup/",
            "Magento\\": "app/code/Magento/",
            "Zend\\Mvc\\Controller\\": "setup/src/Zend/Mvc/Controller/"
        },
        "psr-0": {
            "": [
                "app/code/",
                "generated/code/"
            ]
        },
        "files": [
            "app/etc/NonComposerComponentRegistration.php"
        ],
        "exclude-from-classmap": [
            "**/dev/**",
            "**/update/**",
            "**/Test/**"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Magento\\Sniffs\\": "dev/tests/static/framework/Magento/Sniffs/",
            "Magento\\Tools\\": "dev/tools/Magento/Tools/",
            "Magento\\Tools\\Sanity\\": "dev/build/publication/sanity/Magento/Tools/Sanity/",
            "Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/",
            "Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/"
        }
    },
    "version": "2.3.1",
    "minimum-stability": "stable",
    "repositories": [
        {
            "type": "composer",
            "url": "https://repo.magento.com/"
        }
    ],
    "extra": {
        "magento-force": "override"
    }
}

Hi @benhtn Thank you for your report. problems with data migration from 1.x must be reported in https://github.com/magento/data-migration-tool repository.