🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Install Magento 2.4 via Command Line

By Sanjay JethvaUpdated on May 22, 2025 4 min read

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:

php bin/magento setup:install --base-url="http://localhost/mag24/" --db-host="localhost" --db-name="mag24" --db-user="root" --admin-firstname="admin" --admin-lastname="admin" --admin-email="[email protected]" --admin-user="admin" --admin-password="admin123" --language="en_US" --currency="INR" --timezone="America/Chicago" --use-rewrites="1" --backend-frontname="admin"

Note: If you witness an syntax error in unexpected way, while installing Magento 2.4 via command line check the solution for it.

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 MagentoFrameworkStoreManagerInterface 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

Solution:

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 ‘MagentoFrameworkExceptionLocalizedException’ 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 MagentoCatalogRuleModelRuleFactory 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 SymfonyComponentConsoleInputArrayInput::__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 MagentoCatalogModelResourceProductInterceptor::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 errorMagentoSetupSampleDataException] Error during sample data installation: Class MagentoSalesModelServiceOrderFactory does not existSwitch to the master branch:cd <magento_root>git checkout mastergit pull origin master

That’s it with Magento 2.4 installation via command line. Likewise you can also learn to Install Magento 2 on Ubuntu with our step wise guide.

I’d be happy to help you out.

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

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.