How to Install Magento 2.4 via Command Line

Magento 2.4 is released!

The one thing consistent in this new normal is the Magento community’s tradition to upgrade and improve with each new version!

The latest Magento 2.4 was released on July 28, ’20. And our developers were quick enough to download the latest Magento 2 version to investigate what’s in store for them.

If you are also one of us, I bet you too would want to check it out, and hence, here’s the method to install Magento 2.4 via command line that you can implement to dive into Magento 2.4.

Install Magento 2 and start with the most prominent features of the latest version like:

We were pretty much excited, and I’m sure you are too!

Magento has one command-line interface that performs both installation and configuration tasks: <magento_root>/bin/magento.

However, the new interface also allows to:

  • Install Magento
  • Clear cache
  • Manage indexes and reindexing
  • Create translation dictionaries and translation packages
  • Generate non-existent classes such as factories and interceptors for plug-ins
  • Generate the dependency injection configuration for the object manager
  • Deploy static view files
  • Create CSS from Less

Benefits of using Magento 2 Command Line:

  • A single command (<magento_root>/bin/magento list) lists all available installation and configuration commands.
  • Symfony based consistent UI
  • The CLI is extensible so third party developers can “plug in” to it
  • Not display the commands for disabled modules

Before you start the Magento 2 installation process, make sure you meet all the system requirements for Magento 2.4

Method to Install Magento 2.4 via Command Line:

Run the below command in the command line:

Note: When you install Magento 2.4 via command line and witness an Unexpected ‘)’ syntax error, check the solution here

There are some other common issues faced while installing Magento 2.

Here’s a quick fix for all of those issues:

Common Magento 2 Installation Issues and their solution:

  1. Reflection Exception Error
  2. Fatal PDO Error
  3. Composer version error

Check each error and its solution below:

    1. Reflection Exception Error

      [ERROR] exception ‘ReflectionException’ with message ‘Class Magento\Framework\StoreManagerInterface does not exist’ in /<path>/lib/internal/Magento/Framework/Code/Reader/ClassReader.phpSolution:

      1. Clear the directories and files under Magento’s var subcategory
      2. Install Magento again
      3. Run these commands with root privileges for your Magento file system$ cd <the name of your Magento install directory>/var$ rm -rf var/cache/* di/* generation/* page_cache/*
      4. In case you are using Redis, clear redis cache –$ redis-cli FLUSHALL
    2. Fatal PDO Error

      PHP Fatal error:  Class ‘PDO’ not found in /var/www/html/magento2/setup/module/Magento/Setup/src/Module/Setup/ConnectionFactory.php

      on line 44


      Check if you have installed all of the below extensions:

        1. ext-bcmath
        2. ext-ctype
        3. ext-curl
        4. ext-dom
        5. ext-gd
        6. ext-hash
        7. ext-iconv
        8. ext-intl
        9. ext-mbstring
        10. ext-openssl
        11. ext-pdo_mysql
        12. ext-simplexml
        13. ext-soap
        14. ext-xsl
        15. ext-zip
        16. lib-libxml
    3. Composer version error

      ErrorException]file_get_contents(app/etc/NonComposerComponentRegistration.php): failed to open stream: No such file or directoryThis is a known error with versions of Composer and produces the above error.

      If you are using the version of composer released between November 21 to November 26, 2015, you’ll get this error.

      Check the composer’s version using the command – composer -v

      Either upgrade or downgrade the version of the composer to the version that is not released between these dates.

      Use these commands for the same:

      Upgrade composer – composer self-update

      Downgrade composer – composer self-update 1.0.0-alpha11

      After that, delete Magento 2 directory and subdirectories and download Magento again.

Errors installing optional sample data

The below errors are often faced while you install sample data in Magento 2. Check the errors and their solutions:

  1. Permission errorModule ‘Magento_CatalogRuleSampleData’:[ERROR] exception ‘Magento\Framework\Exception\LocalizedException’ with message ‘Can’t create directory /var/www/html/magento2/generated/code/Magento/CatalogRule/Model/.’ in /var/www/html/magento2/lib/internal/Magento/Framework/Code/Generator.php:103(more)`Next exception ‘ReflectionException’ with message ‘Class Magento\CatalogRule\Model\RuleFactory does not exist’ in /var/www/html/magento2/lib/internal/Magento/Framework/Code/Reader/ClassReader.php:29(more)This error is caused by the file system permissions settings. Fix it by setting up your access permissions as a user with root privileges.
  2. Production mode errorPHP Fatal error: Uncaught TypeError: Argument 1 passed to Symfony\Component\Console\Input\ArrayInput::__construct() must be of the type array, object given, called in /<path>/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 97 and defined in /<path>/vendor/symfony/console/Symfony/Component/Console/Input/ArrayInput.php:37You’ll face this error when you try to install optional sample data in production mode with the composer instead of installing it in the developer mode.To fix this, log in as Magento file system owner and run these commands:cd <magento_root>bin/magento deploy:mode:set developerrm -rf generated/code/* generated/metadata/*bin/magento sampledata:deploy
  3. SELinux errorPHP Fatal error: Call to undefined method Magento\Catalog\Model\Resource\Product\Interceptor::getWriteConnection() in /var/www/magento2/app/code/Magento/SampleData/Module/Catalog/Setup/Product/Gallery.phpon line 144Disable SELinux to fix this error.
  4. Develop branch errorMagento\Setup\SampleDataException] Error during sample data installation: Class Magento\Sales\Model\Service\OrderFactory does not existSwitch to the master branch:cd <magento_root>git checkout master

    git pull origin master

That’s it with Magento 2.4 installation via command line.

If you have any doubts in the installation process or cannot fix any of the above errors, please mention them in the Comments section below.

I’d be happy to help you out.

Also, share the post with fellow Magento developers via social media.

Thank you.

(based on 25 Reviews)
How to Install Magento 2.4 via Command LineAuthor Magento Badge

Sanjay Jethva

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.


Leave a Reply

Your email address will not be published. Required fields are marked *