{"id":1174,"date":"2020-08-13T03:29:39","date_gmt":"2020-08-13T03:29:39","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/08\/13\/install-magento-2-4-via-command-line\/"},"modified":"2025-05-22T12:01:59","modified_gmt":"2025-05-22T06:31:59","slug":"install-magento-2-4-via-command-line","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/install-magento-2-4-via-command-line\/","title":{"rendered":"How to Install Magento 2.4 via Command Line"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/meetanshi.com\/blog\/magento-2-4-release\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2.4<\/a>&nbsp;is released!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The one thing consistent in this new normal is the Magento community\u2019s tradition to upgrade and improve with each new version!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The latest Magento 2.4 was released on July 28, \u201920. And our developers were quick enough to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/download-magento\/\" target=\"_blank\" rel=\"noreferrer noopener\">download the latest Magento 2 version<\/a>&nbsp;to investigate what\u2019s in store for them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you are also one of us, I bet you too would want to check it out, and hence, here\u2019s the method to&nbsp;<em><strong>install Magento 2.4 via command line<\/strong><\/em>&nbsp;that you can implement to dive into Magento 2.4.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/meetanshi.com\/blog\/install-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install Magento 2<\/a>&nbsp;and start with the most prominent features of the latest version like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/meetanshi.com\/blog\/setup-two-factor-authentication-in-magento-2-4\/\" target=\"_blank\" rel=\"noreferrer noopener\">2FA security for Magento 2 admin panel<\/a><\/li>\n\n\n\n<li>Purchase approval workflows<\/li>\n\n\n\n<li>Seller assisted shopping<\/li>\n\n\n\n<li>In-store pickup<\/li>\n\n\n\n<li>New media gallery<\/li>\n\n\n\n<li><a href=\"https:\/\/meetanshi.com\/blog\/magento-pwa-studio\/\" target=\"_blank\" rel=\"noreferrer noopener\">PWA Development<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/meetanshi.com\/blog\/best-headless-ecommerce-platforms\/\" target=\"_blank\" rel=\"noreferrer noopener\">Headless commerce<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">We were pretty much excited, and I\u2019m sure you are too!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Magento has one command-line interface that performs both installation and configuration tasks:&nbsp;<code>&lt;magento_root&gt;\/bin\/magento<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, the new interface also allows to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Install Magento<\/li>\n\n\n\n<li>Clear cache<\/li>\n\n\n\n<li>Manage indexes and reindexing<\/li>\n\n\n\n<li>Create translation dictionaries and translation packages<\/li>\n\n\n\n<li>Generate non-existent classes such as factories and interceptors for plug-ins<\/li>\n\n\n\n<li>Generate the dependency injection configuration for the object manager<\/li>\n\n\n\n<li>Deploy static view files<\/li>\n\n\n\n<li>Create CSS from Less<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Benefits of using Magento 2 Command Line:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A single command (<code>&lt;magento_root&gt;\/bin\/magento list<\/code>) lists all available installation and configuration commands.<\/li>\n\n\n\n<li>Symfony based consistent UI<\/li>\n\n\n\n<li>The CLI is extensible so third party developers can \u201cplug in\u201d to it<\/li>\n\n\n\n<li>Not display the commands for disabled modules<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Before you start the Magento 2 installation process, make sure you meet all the&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-system-requirements\/\" target=\"_blank\" rel=\"noreferrer noopener\">system requirements for Magento 2.4<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Install Magento 2.4 via Command Line:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run the below command in the command line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php bin\/magento setup:install --base-url=\"http:\/\/localhost\/mag24\/\"&nbsp;--db-host=\"localhost\" --db-name=\"mag24\" --db-user=\"root\" --admin-firstname=\"admin\" --admin-lastname=\"admin\" --admin-email=\"admin@admin.com\" --admin-user=\"admin\" --admin-password=\"admin123\" --language=\"en_US\" --currency=\"INR\" --timezone=\"America\/Chicago\" --use-rewrites=\"1\" --backend-frontname=\"admin\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: If you witness an&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/solved-syntax-error-while-installing-magento-2-4\/\" target=\"_blank\" rel=\"noreferrer noopener\">syntax error in unexpected<\/a>&nbsp;way, while installing Magento 2.4 via command line check the solution for it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are some other common issues faced while installing Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s a quick fix for all of those issues:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Magento 2 Installation Issues and their solution:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Reflection Exception Error<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Fatal PDO Error<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Composer version error<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check each error and its solution below:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Reflection Exception Error<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>[ERROR] exception \u2018ReflectionException\u2019 with message \u2018Class MagentoFrameworkStoreManagerInterface does not exist\u2019 in \/&lt;path&gt;\/lib\/internal\/Magento\/Framework\/Code\/Reader\/ClassReader.php<\/em><strong>Solution:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Clear the directories and files under Magento\u2019s var subcategory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Install Magento again<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Run these commands with root privileges for your Magento file system<em>$ cd &lt;the name of your Magento install directory&gt;\/var$ rm -rf var\/cache\/* di\/* generation\/* page_cache\/*<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. In case you are using Redis, clear redis cache \u2013<em>$ redis-cli FLUSHALL<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Fatal PDO Error<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>PHP Fatal error:&nbsp; Class \u2018PDO\u2019 not found in \/var\/www\/html\/magento2\/setup\/module\/Magento\/Setup\/src\/Module\/Setup\/ConnectionFactory.php<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>on line 44<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Solution:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check if you have installed all of the below extensions:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. ext-bcmath<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. ext-ctype<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. ext-curl<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. ext-dom<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5. ext-gd<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">6. ext-hash<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">7. ext-iconv<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">8. ext-intl<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">9. ext-mbstring<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">10. ext-openssl<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">11. ext-pdo_mysql<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">12. ext-simplexml<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">13. ext-soap<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">14. ext-xsl<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">15. ext-zip<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">16. lib-libxml<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Composer version error<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>ErrorException]<\/em><em>file_get_contents(app\/etc\/NonComposerComponentRegistration.php): failed to open stream: No such file or directory<\/em>This is a known error with versions of Composer and produces the above error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you are using the version of composer released between November 21 to November 26, 2015, you\u2019ll get this error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check the composer\u2019s version using the command \u2013&nbsp;<em>composer -v<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Either upgrade or downgrade the version of the composer to the version that is not released between these dates.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use these commands for the same:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Upgrade composer \u2013&nbsp;<em>composer self-update<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Downgrade composer \u2013&nbsp;<em>composer self-update 1.0.0-alpha11<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After that, delete Magento 2 directory and subdirectories and download Magento again.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Errors installing optional sample data<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The below errors are often faced while you&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/install-sample-data-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">install sample data in Magento 2<\/a>. Check the errors and their solutions:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Permission error<\/strong><em>Module \u2018Magento_CatalogRuleSampleData\u2019:<\/em><em>[ERROR] exception \u2018MagentoFrameworkExceptionLocalizedException\u2019 with message \u2018Can\u2019t create directory \/var\/www\/html\/magento2\/generated\/code\/Magento\/CatalogRule\/Model\/.\u2019 in \/var\/www\/html\/magento2\/lib\/internal\/Magento\/Framework\/Code\/Generator.php:103<\/em><em>(more)`<\/em><em>Next exception \u2018ReflectionException\u2019 with message \u2018Class MagentoCatalogRuleModelRuleFactory does not exist\u2019 in \/var\/www\/html\/magento2\/lib\/internal\/Magento\/Framework\/Code\/Reader\/ClassReader.php:29<\/em><em>(more)<\/em>This error is caused by the file system permissions settings. Fix it by setting up your access permissions as a user with root privileges.<\/li>\n\n\n\n<li><strong>Production mode error<\/strong><em>PHP Fatal error: Uncaught TypeError: Argument 1 passed to SymfonyComponentConsoleInputArrayInput::__construct() must be of the type array, object given, called in \/&lt;path&gt;\/vendor\/magento\/framework\/ObjectManager\/Factory\/AbstractFactory.php on line 97 and defined in \/&lt;path&gt;\/vendor\/symfony\/console\/Symfony\/Component\/Console\/Input\/ArrayInput.php:37<\/em>You\u2019ll 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:<em>cd &lt;magento_root&gt;<\/em><em>bin\/magento deploy:mode:set developer<\/em><em>rm -rf generated\/code\/* generated\/metadata\/*<\/em><em>bin\/magento sampledata:deploy<\/em><\/li>\n\n\n\n<li><strong>SELinux error<\/strong><em>PHP Fatal error: Call to undefined method MagentoCatalogModelResourceProductInterceptor::getWriteConnection() in \/var\/www\/magento2\/app\/code\/Magento\/SampleData\/Module\/Catalog\/Setup\/Product\/Gallery.php<\/em>on line 144Disable SELinux to fix this error.<\/li>\n\n\n\n<li><strong>Develop branch error<\/strong><em>MagentoSetupSampleDataException] Error during sample data installation: Class MagentoSalesModelServiceOrderFactory does not exist<\/em>Switch to the master branch:<em>cd &lt;magento_root&gt;<\/em><em>git checkout master<\/em><em>git pull origin master<\/em><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it with Magento 2.4 installation via command line. Likewise you can also learn to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/install-magento-2-on-ubuntu\/\">Install Magento 2 on Ubuntu<\/a>&nbsp;with our step wise guide.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019d be happy to help you out.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, share the post with fellow Magento developers via social media. Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2.4&nbsp;is released! The one thing consistent in this new normal is the Magento community\u2019s tradition to upgrade and improve with each new version! The&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1174","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1174"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1174\/revisions"}],"predecessor-version":[{"id":14743,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1174\/revisions\/14743"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}