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:
- 2FA security for Magento 2 admin panel
- Purchase approval workflows
- Seller assisted shopping
- In-store pickup
- New media gallery
- PWA Development
- Headless commerce
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:
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: 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:
Check each error and its solution below:
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:
- Clear the directories and files under Magento’s var subcategory
- Install Magento again
- 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/*
- In case you are using Redis, clear redis cache –$ redis-cli FLUSHALL
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:
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:
- 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.
- 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
- 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.
- 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.