magento-2-composer-install

How to Install Magento 2 Via Composer | Magento Tutorial 2020

Posted by

Several ways have been applied to install Magento 2. Among which, there is a common and simple way that is popular nowadays to many Magento users. The one we are talking about is Magento 2 Composer Install.

In this article, we will explain why you should use this kind of installation. And later on, an up-to-date and step-by-step instruction will be clarified.

(See more tutorials for Magento on Mage Guides)

Why Magento 2 Composer Install?

magento-2-composer-install

Many users nowadays suggest using Composer for installation. You may wonder, don’t you? Automatically, it will bring about several benefits.

With Magento 2 Composer Install, you will be able to:

  • Reuse third-parties libraries without bundling them with source code
  • Reduce extension conflicts, compatibility errors with component-based architecture
  • Adhere to PHP – Framework Interoperability Group (FIG)
  • Repackage Magento Open Source with other components
  • Use the Magento software in a production environment

After understanding all the advantages of Magento 2 Composer Install, why don’t you get started with us for the tutorial?

(Want to find extensions for Magento? Click here for more reviews)

Step-by-step Guideline on Installing Magento 2 via Composer

Step-by-step-Guideline-on-Installing-Magento-2-via-Composer

Before anything, there is something that you need to have for the installation process.

Getting Started

getting-started

For the preparation, do the following steps:

  • Set up a server that meets the system requirements
  • Create the Magento file system owner
  • Install Composer
  • Obtain authentication keys for the Magento code repository

Now, let’s get started!

STEP 1: Get the metapackage

get-the-metapackage

Getting the metapackage is quite simple. Some actions have to be taken for this step:

  • Log in to your Magento server as, or switch to, the Magento file system owner.
  • Change to the web server docroot directory or a directory that you have configured as a virtual host docroot
  • Create a new composer project using one out of two followings metapackage:

Magento Open Source:

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

Magento Commerce:

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

Next, please enter your Magento authentication keys when there’s notification.

To avoid errors, make sure there are no typos in your command.

Examples:

There are several examples of metapackage that includes various amazing features. To specify, you can definitely use Composer

  • Minor release: contains new features, quality fixes, and security fixes.

The following command is an example of specifying Magento Commerce 2.3.0 metapackage:

composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition=2.3.0 <install-directory-name>
  • Quality patch: primarily contains functional and security fixes. Also, other features sometimes are included, namely, new features, back-compatible features.

To specify Magento Commerce 2.3.3, please use this command:

composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition=2.3.3 <install-directory-name>
  • Security patch: Only the security fixes feature is included. This patch is designed for the faster and simpler installation process.

This security patch use Composer of 2.3.2-px version. For instance, use the following command to specify Magento Commerce 2.3.2-p1:

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

STEP 2: Set permissions

set-permissions

Move to the second step. This step enables you to set the file permissions for the web-server group. This step is extremely necessary before installing Magento.

Moreover, without file permissions, the following stages cannot be done. To be specific, the Setup Wizard and command line aren’t able to write files to the Magento file system.

Use this command to complete this step:

cd /var/www/html/<magento install directory>
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R :www-data . # Ubuntu
chmod u+x bin/magento

STEP 3: Install Magento

install-magento

Now you have all the materials for installation, let’s come to the most important step.

There are 2 methods for this process:

Command Line

Let us give you a specific example.

Suppose that the Magento install directory is named magento2ee, the db-host is on the same machine (localhost). And all the db-name, db-user, and db-password are all magento.

Then, we have the following command:

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

We have to note that you can choose to customize URI with the –backend-frontname option. However, we highly recommend setting the function of automatically generating a random URI instead. It’s more securable to avoid hackers and malicious software.

Web Setup Wizard

The second choice to install. This option enables you to use your browser to navigate to Magento’s setup wizard.

https://<Magento-host-or-IP>/<path-to-magento-root>/setup

Note: You aren’t able to use this option if your docroot is set to the pub/ directory.

Composer Installation Troubleshooting

Composer-installation-troubleshooting

When it comes to software installation, it’s not easy at all. As the process of installation is relatively complicated, it is unavoidable to run into difficulties.

Understanding such a problem, we will identify the most common trouble. Thenceforth, the reasons and possible solutions will be clarified to help Magento users.

Error displays

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

Reasons

The changes in certain versions of Composer resulted in such errors, makes it difficult for Magento users.

To confirm the version of Composer, you can enter the following command:

composer -v

And the information will appear as:

Composer version 1.0-dev (2b14f0a047dd4f3545ec82381f65c36ea93a4c81) 2015-11-25 17:13:09

Solutions

There’s one simple way to workaround. In particular, you can downgrade or upgrade Composer version. And then try to download Magento once again.

Follow these simple steps to solve your problems.

Step 1: Change your version of Composer

  • Downgrade Composer:
composer self-update 1.0.0-alpha11
  • Upgrade Composer:
composer self-update

Step 2: Delete your Magento 2 directory and subdirectories

Step 3: Download again using composer create-project or git clone

Step 4: Update Composer

composer self-update

Conclusion

Before starting your e-commerce business, the very first and most important step is to successfully install the software, specifically, Magento software. Without this step, you will never be able to create any website that you want.

We hope that this article, with those easy steps above, will provide helpful information on Magento 2 Composer Install. As a result, you won’t find it complicated anymore.

For more information, you can contact us anytime. We are always glad to answer.

You may also be interested in:

Leave a Reply

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