magento-2
  1. magento-2-installation-using-composer

Installation using Composer

Magento 2 is a PHP-based e-commerce platform that requires a web server and a database for installation. In this tutorial, we will learn how to install and configure Magento 2 using the command-line tool, Composer.

Prerequisites

Before we start the installation, we need to make sure that we have the following prerequisites installed in our system:

  • PHP version 7.1 or higher
  • MySQL or MariaDB version 5.6 or higher
  • Apache or Nginx web server
  • Composer

Installation Steps

Follow the below steps to install Magento 2 using Composer:

  1. Open the terminal or command prompt, and navigate to the webroot directory (e.g., /var/www/html/ or C:\xampp\htdocs\)

  2. Run the following command to create a new Magento 2 project:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2

This will create a new directory named magento2 with all the necessary files and folders.

  1. After the installation is complete, navigate to the magento2 directory:
cd magento2
  1. Run the following command to install Magento 2:
bin/magento setup:install \
--base-url=http://localhost/magento2 \
--db-host=localhost \
--db-name=magento \
--db-user=root \
--db-password=root \
--admin-firstname=admin \
--admin-lastname=admin \
--admin-email=admin@example.com \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1 \
--backend-frontname=admin

Here, we are specifying the database details, admin details, store details, and URL details for our installation. Please replace the values with your own details.

  1. After the installation is complete, run the following command to set the correct file permissions:
chmod -R 777 var/ pub/ generated/
  1. Open your preferred web browser and access the Magento 2 installation at the following URL:
http://localhost/magento2/

Here, replace localhost/magento2 with the base URL you provided in step 4.

  1. Congratulations! You have successfully installed Magento 2 using Composer.

Explanation

In the installation steps above, we first used Composer to create a new Magento 2 project. Composer is a dependency manager for PHP that allows us to easily install and manage libraries and packages.

We then navigated into the magento2 directory and used the bin/magento command to install Magento 2 with the specified database, admin, and store details. We also set the correct file permissions for the installation.

Finally, we accessed the Magento 2 installation in our web browser, and the installation was complete.

Use

Installation using Composer is the preferred method for developers to install Magento 2. It allows for easy management of dependencies and packages, and also ensures that the latest version of Magento 2 is installed.

Important Points

  • Make sure that all the prerequisites are installed before starting the installation process.
  • Always set the correct file permissions for the Magento 2 installation to avoid any file permission issues.
  • It is recommended to use Composer for installing and managing Magento 2 dependencies and packages.

Summary

In this tutorial, we learned how to install and configure Magento 2 using Composer. We first created a new Magento 2 project using Composer, and then installed Magento 2 with the necessary database, admin, and store details. Finally, we set the correct file permissions and accessed the installation in our web browser to complete the installation process.

Published on: