How to Install Magento 2 with Composer?

how to install magento 2

Last year became one of the most important years for Magento community. Magento ecosystem of partners and developers from the USA,  Germany, Australia (and from other countries) witnessed the release of  long-awaited Magento 2. Being a team of dedicated developers, we could not ignore this great event and prepared an article “5 Main Reasons to Upgrade to Magento 2.0 - Next Generation Commerce Platform“ to inform you about it. Our next step was Magento 2 installation on our server. So, how did we do that? What issues did we face? The answers on these questions you can find in today’s article. 

3 Basic Stages of Magento 2 Installation 

Before starting to describe the whole process of installation, we decided to give you a little theory. If you need just practice results, you can skip it. 

What is Composer?

Composer is a package and dependency manager for PHP. It means that it is not only intended for Magento, but manages different PHP packages.  In 2011, Jordi Boggiano decided to develop Composer as an alternative to the PEAR. The second one was created according to the assumption, that PHP library components would be installed system-wide. But practice showed that it was not the best decision. 

Different projects require different versions of the same libraries. And when you upgrade wide system libraries, you have to upgrade all dependent projects as well. Composer has improved architecture. Its packages are project specific and installed under vendor, unless explicitly installed system-wide. So, it is reasonable to use Composer for Magento 2 installation. Before doing that, you need to check whether your server meets basic Magento 2 requirements:

  • Apache: 2.2 or 2.4
  • PHP: 5.4.11
  • MySQL: 5.6.x
  • Composer

 We also made this recheck and only after started Magento 2 installation. Read below how we did it:

Composer Installation

Firstly, we typed the following command in the shell to check if Composer is already installed:

composer -help 

To do it, we used these two commands:If you do it and see that it is not installed, you will get the response command “not found”. So, it means that you have to install Composer. 

curl -sS | php

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

If there is a need, you can additionally install Composer globally.  In that case, you must should not type php /path/to/composer.phar each time. The PATH system variable will be automatically setted up by the Windows installer.

Magento 2 Downloading 

After that, we cloned Magento 2 into our current directory from GitHub repository. We used the next command to run it:

git clone

The repo was cloned into a Magento2 subdirectory, and this took about 2-3 minutes. The time needed for cloning depends on your broadband speed. 

Then we moved the next two commands into the Magento 2 root directory:

cd magento2

git checkout master

To be able to work with Composer, you have to add a composer.json file within its root directory to the project. If you look at the file, you will be able to see a great amount of Magento 2 package dependencies. We selected the next three of them:

  • require: a list of packages and versions that are required by Magento 2. You will not able to install  Magento 2 if any of those package dependencies are not met.
  • require-dev: a list of packages that are required by Magento 2 for development.
  • replace: shows packages, which are replaced by Magento 2. Most of them are made up of the main modules, which  make up the Magento 2 framework.

Those who run Composer for the first time should use the next:

composer install

When upgrades are available, it becomes possible to install future updates with:

composer update

And when Composer is installed, it is time to install Magento. 


You know well that ‘Admin’ is the owner of all Magento files on a server, and Apache web server runs on behalf of ‘www-data’ user. In Magento 2 documentation you can find the information regarding the access permission settings for files and directories. We used the next access permissions:

chown -R admin:www-data /var/www/magento2

find /var/www/magento2 -type f -print0 | xargs -r0 chmod 640

find /var/www/magento2 -type d -print0 | xargs -r0 chmod 750

chmod -R g+w /var/www/magento2/{pub,var}

If you want to install Magento from the web interface you should add write permissions for app/etc/ and vendor/:

chmod -R g+w /var/www/magento2/{app/etc,vendor}

Create The Database

Provided that you already have a MySQL user with the corresponding permissions, you are able to create an empty database to work with.

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

Magento 2 Installation

There are three ways of Magento 2 installation: via command line, with Composer and through the installer interface.

Now, the installer interface looks better. It allows you to check whether your server is ready or not. 

Magento 2 installer interface

Follow the installation steps and when everything will be installed, you will be able  to work.

However, during the installation you may also face some difficulties. We know about cases when developers have tried to install Magento 2 by using the web interface, but the installation has not been ended. In other cases the installation was conducted from CLI, and developers also got errors. For example, like this one:

PHP Fatal error: Maximum function nesting level of '100' reached, aborting! in /var/www/magento2/vendor/zendframework/zend-code/Zend/Code/Scanner/DocBlockScanner.php on line 201

As it turned out, it was connected with xdebug PHP extension installed on server. The error was fixed by setting xdebug.max_nesting_level = 500. 

In conclusion, we hope that our tutorial on Magento 2 installation has been informative enough and all steps of the installation process have been clear. If you have some additional questions, our Magento 2 development team will be happy to help you! Read more about Magento 2 here:

Comments (2):
Posted on Wednesday, September 14, 2016 by :
Thanks for being on point and on taergt!
Posted on Monday, September 26, 2016 by :
That was a good article. Another way to install Magento 2 via composer is to visit to obtain authentication keys. You need to have a Magento account to login. After logging in Click “My Access Keys”, and generate new set of keys by giving it some Descriptive “Name”.Enter the following command in terminal.composer create-project --repository-url= magento/project-community-editionenter your username as public key and password as private key.Now you can install Magento 2 through Setup Wizard.
Leave a comment:
*Your comment will be published after approval by site administrator.