Skip to content

How to install Magento 2.4

Magento 2.4.4 is released recently, and this time, it is not only about enhancing features, security updates, and user experience, but this will be the foundation of commerce innovations by Adobe and the Open-source community. The platform has vast features and functionalities with ecommerce centric approach. Even with the latest expansion in digital commerce, Online retailers have a massive marketplace for extended features to adapt and fulfill their business needs.

The very first question to ask before setting up your desired online store is “How to install Magento 2?” To answer this, there are three methods to install it. It can be done via Composer, the Git repository, and manual installation. The article will follow and drive you through the standard process via composer and the prerequisite of the software requirements.

Magento 2 Installation via Composer

Benefits

Using Composer to install Magento metapackage and manage Magento components and their dependencies provide listed benefits:

  • One can reuse third-party libraries without bundling them with source code.
  • With the robust dependence of a component-based architecture, extension conflicts and compatibility issues get reduced.
  • Stick to PHP-Framework Interoperability Group (FIG) standards
  • Repackage Magento Open Source with other components
  • You can use Magento in a production environment

Having said this, let’s find out the software prerequisites before installation.

System Requirements

Listed are the requirements to match the software download before starting the process.

  • Web Server: Apache 2.4
  • MySql version: 8.0
  • PHP version: 8.1
  • Composer: 2.X

There are detailed system requirements, including elastic-search, open-search, cache components, etc., available here for each Magento version. Before starting the process, ensure system requirements, install Composer and get the authentication keys to the Magento composer repository.

Installation Process

  1. Log in as a user to your Magento server to get the ownership and allow permission to access the source to other users. Find more on the user and approvals here.

  2. Change the configured directory from the virtual host docroot to the web server docroot directory or a directory.

  3. Change the virtual host docroot directory to server docroot or a directory.

    1. Using Magento Open Source or Adobe Commerce metapackage, create a new composer project.

      Magento Open Source

      composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition <install-directory-name> 2
      

      Adobe Commerce

      composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition <install-directory-name> 2
      
      Enter your Magento authentication keys ( Public and Private) that are created and configured in your Commerce Marketplace.

    2. If the Magento installation is done for decent scenarios, say Minor release, Quality patch, or security patch follow the command as given below:

      1. Minore Release: This release contains feature updates, security fixes, and quality fixes. To specify the installation for such a release metapackage for Adobe Commerce 2.4.3, use this:

        composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition=2.4.3 <install-directory-name> 2
        
      2. Security Patch: This release is related to security fixes only. To specify the installation for Adobe Commerce 2.4.3, use this:

        composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition=2.4.3 <install-directory-name> 2
        
      3. Quality Patch: This release contains functional and security fixes and sometimes contains additional features. To specify the installation for Adobe Commerce 2.4.3, use this:

        composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition=2.4.3-p1 <install-directory-name> 2
        
  4. Set read-write permissions for the web server group before installing the Magento. This is necessary to allow the command line to write files to the Magento file system.

  5. Use the command line to install Magento finally. Follow the code given below, assuming the directory name is Magento2ee, and all the required passwords are magento.

bin/magento setup:install \
--base-url=http://localhost/magento2ee \
--db-host=localhost \
--db-name=magento \
--db-user=magento \
--db-password=magento \
--admin-firstname=admin \
--admin-lastname=admin \
--admin-email=admin@admin.com \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1 \
--search-engine=elasticsearch7 \
--elasticsearch-host=es-host.example.com \
--elasticsearch-port=9200 \
--elasticsearch-index-prefix=magento2 \
--elasticsearch-timeout=15
According to your will and need, you can change the URL, name, id, password, timezone, etc.

Now you have successfully installed Magento software, and you can have a black theme, so this might lead you to think about how you can find the same data? Let’s roll out and see how you can add sample data to see the native functionality!

Install Sample Data

As the article focuses on the installation via composer, let us see how you can install the sample data. You need to enter the following command as a file system owner in the <magento_root> folder:

bin/magento sampledata:deploy

If you install sample data after Magento installation, make sure to update the database schema in the root folder.

bin/magento setup:upgrade

Once you are done with the given command, you need to authenticate it. Sometimes you may find the authentication error as displayed:

1
2
3
[Composer\Downloader\TransportException]
The 'https://repo.magento.com/packages.json' URL required authentication.
You must be using the interactive console to authenticate

Change the Magento directory and run composer update , which will prompt you for the authentication keys.

Once you download the sample data packages, log in to your Magento server as the file system owner and the follow command in <magento_root> folder:

bin/magento setup:upgrade

Success

If you still get any errors, write your comments below. Our certified Magento experts will lead you to a successful installation. At Navigate, We make sure to simplify your commerce experience for all ( merchants, developers, and users). Being a Magento developer, one should always seek the best practices while upgrading or installing Magento 2. You can review the best practices to follow in this article. Ask us or drop out an email if you need any kind of assistance with our dedicated Magento services.

Info

Please make sure of typos in your command to reject the errors encountered, such as Could not find package... or ...no matching package found. If the error still persists, you are not authorized to download Adobe Commerce. Reach out to the support.

Standard Magento 2 Installation Issues and solution

Listed are the most common installation issues developers find while installing Magento 2.4, and see how one can avoid them with the solution!

Composer version error

Error

Exception file_get_contents(app/etc/NonComposerComponentRegistration.php): failed to open stream: No such file or directory

Such kind of error displays an issue related to your composer version. If you are using the November 2015 release of Composer, you will get this error. Make sure to check your composer version by following the command:

composer -v
You can upgrade or downgrade the Magento version from the given dates to have an error-free installation.

To Upgrade Composer, run the command as follows:

composer self-update

To Downgrade the version, run the given line as a command:

composer self-update 1.0.0-alpha11

Once done, delete Magento 2 directory and subdirectories, and download Magento again!

Reflection Anomaly

Error

exception ‘ReflectionException’ with message ‘Class Magento\Framework\StoreManagerInterface does not exist’ in //lib/internal/Magento/Framework/Code/Reader/ClassReader.php

While installing, if you get such kind of error message is due to a reflection exception. To avoid it, see the solution below!

Solution: clear the directories and all the files under the Magento Varnish subcategory and reinstall the Magento. Once done, rum the below command with root privileges for the Magento file system :

$ cd <the name of your Magento install directory>/var$ rm -rf var/cache/* di/* generation/* page_cache/*

If you are using Redis, clear the cache by:

–$ redis-cli FLUSHALL

Fatal PDO Error

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: Make sure you have installed all the mentioned extensions correctly!

ext-dom
ext-iconv
ext-openssl
ext-bcmath
ext-gd
ext-intl
ext-pdo_mysql
ext-ctype
ext-hash
ext-mbstring
ext-simplexml
ext-curl
ext-zip
ext-xsl
ext-soap
lib-libxml

Errors with optional sample data

  1. Permission error

Error

Module ‘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)

Such an error occurs if the file system permissions are not set correctly. To prevent it, put the user access permissions with root privileges.

  1. Production mode error

Error

PHP Fatal error: Uncaught TypeError: Argument 1 passed to Symfony\Component\Console\Input\ArrayInput::__construct() must be of the type array, object given, called in //vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 97 and defined in //vendor/symfony/console/Symfony/Component/Console/Input/ArrayInput.php:37

While installing sample data in production mode with the Composer instead of developer mode, the system throws this error! To solve this, Log in to the Magento file system as an owner and run the command:

cd <magento_root>bin/magento deploy:mode:set developerrm -rf generated/code/* generated/metadata/*bin/magento sampledata:deploy
  1. SELinux error

Error

PHP 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 144

To solve this, simply disable SELinux.

  1. Develop branch error

Error

Magento\Setup\SampleDataException]

Class Magento\Sales\Model\Service\OrderFactory does not exist

This occurs while installing sample data! To resolve it, Switch to the master branch and take a pull!

cd <magento_root>git checkout master
git pull origin master

That is all about the Magento 2.4 installation via the command line!


Last update: 2024-02-24