Install Magento 2 Composer

How to Install Magento 2 Using Composer: Step by Step Tutorial

Want to install Magento 2 using Composer but not sure how to do it right? Well, you’ve come to the right place.

In this tutorial, we’ll guide you through the entire process of how to install Magento 2 using Composer with all the right steps.

Before we dive in, though, we would like to go over some basics of Magento web development.

What is Composer?

A composer is basically a tool for dependency management for PHP language and in Magento 2, Composer plays a key role in gathering components and product editions.

It basically allows developers to declare the libraries that your project depends on and it installs, updates, and manages them for you. Put it simply, Magento 2 is dependent on Composer for all of its dependency/package goodness.

There are also many outstanding advantages of using Magento 2 Composer that makes it worthwhile such as:

  • Adhere to Framework Interoperability Group (PHP-FIG) standards.
  • Use Magento 2 in the Productive Environment.
  • Decrease Magento 2 Extension Complexity as well as Compatibility issues through a Component-based architecture with robust Dependency Management.
  • Repackage code with other components.
  • Reuse 3rd party libraries without having to bundle them together with Magento 2 source code.

Given all these benefits, it’s definitely worth considering it. That being said, let’s quickly jump to the point and see how you can install Magento 2 using Composer.

Now, there is already official documentation available on how to install Magento 2 using Composer.

However, it’s long, boring, and unnecessary, which is why we have created an easy, step-by-step tutorial that anyone can follow and install Magento 2 using Composer without any help.

How to Install Magento 2 Using Composer: Required Steps

  • Downloading and Installing Composer
  • Download Magento 2
  • Set Up Permissions
  • Create Database
  • Install Magento 2

Let’s get started with downloading and Installing Composer.

Step 1 – Download & Install Composer

If you’ve not yet installed composer, then you can easily do so by using the following command in your terminal.

curl -sS https://getcomposer.org/installer | php

NOTE:  For Windows users, the composer installation process is a bit different. And there are two ways to install Composer on Windows. Below, we’ve shared both ways.

  • Composer Installation on Windows using the Installer

This is the easiest way to install Composer on your Windows system.

Just download and run the Composer-Setup.exe file on your system and it will automatically install the latest version and set up the PATH, which you can call Composer from any directory in your command line.

  • Composer Manual Installation on Windows

In order to manually install Composer on a Windows system, you need to first change to a directory on your PATH and run the installer by following instructions from here to download composer.phar.

Next, you need to create a new composer.bat file alongside composer.phar:

C:\bin>echo @php "%~dp0composer.phar" %*>composer.bat

Now, you need to add the directory to your PATH environment variable in case it’s not ready.

Finally, close the current terminal and test the usage using a new terminal.

C:\Users\username>composer -V
Composer version 1.0.0 2016-01-10 20:34:53

You’ve now finally installed the Composer on your system. Now, if you want to make it globally available, you can do so by executing the following command:

mv composer.phar /usr/local/bin/composer

Step 2 – Download Magento 2

To download Magento 2, you need to run the following command in the root directory:

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

Step 3 – Set Up Permissions

Once you’ve downloaded the Magento 2 on your system, you need to set certain permission for Magento 2 installation directory.

Here’s the command you need to run for that:

find . -type d -exec chmod 700 {} \; && find . -type f -exec chmod 600 {} \;

Step 4 – Create a Database

Next, you need to create an empty database to work with MySQL.

Please run the following command to create one:

echo "CREATE DATABASE magento2" | mysql -u[mysqluser] -p

Step 5 – Install Magento 2

Once the permissions are set up and database is created, it’s time to finally proceed with Magento 2 installation process.

Please run the following commands in your command line to install Magento 2 using Composer.

php bin/magento setup:install
--base-url="http://yoururl.com/"
--db-host="localhost"
--db-name="dbname"
--db-user="dbuser"
--db-password="dbpass"
--admin-firstname="admin"
--admin-lastname="adminx"
--admin-email="[email protected]"
--admin-user="admin"
--admin-password="admin123
--language="en_US"
--currency="USD"
--timezone="America/Chicago"
--use-rewrites="1"
--backend-frontname="admin"

The values mentioned above are dummy ones, so you need to change them according to your preference.  Also, remember to execute these commands from the Magento 2 root directory.

Once done, it will inform you that the installation has been completed. Now, go ahead and start implementing these steps to install Magento 2 using Composer the right way.

Final Words…

We have covered the entire process of installing Magento 2 using Composer and we hope it helps you do it the right way.

We’ve done our best to make sure to simplify the process as much as to ensure that an absolute beginner can easily learn how to install Magento 2 Composer.

However, if you still have any queries, feel free to reach out. Or, if you need our professional help with Magento Website Development, we would love to help you out!

Tags