If you’re new to Composer or package managers like Node’s NPM then you’ve got a lot to take in before you start working with Magento 2. You see, Magento 2 is dependent on Composer and all of its package/dependency goodness.
It’s true that Magento and several other developers have written articles detailing what I’m about to go through, but I decided to write this for the absolute beginner with deeperÂ explanation of what is going on throughout the steps – particularly the role of Composer.
STEP 1: SERVER ENVIRONMENT
Magento 2 has new minimum requirements of your LAMP stack. I’m not going to list them here in case they change so please check the Magento 2 documentation for those prerequisites. A Vargrant setup is preferable but MAMP Pro can also work.
STEP 2: COMPOSER
If you’re unaware of what composer is then try this analogy. Composer is exactly like…. a composer. In this case Magento 2 is a musical and the packages installed are the members of the orchestra. Once installed in your project, Composer can be used to manage packages based on its dependency system. You can’t have a live musical without the orchestra and you can’t have Magento 2 without its packages. In both cases the composer is responsible for assembling components to allow the restÂ to work.
Fire up your command line tool and navigate to an empty folder where you’d like to install your copy of Magento 2. We need to ensure Composer is installed globally on your system so that you don’t have to repeat this step again.
Type the following command to see if composer is installed:
If it’s not installed you’ll see the responseÂ command not found, which means you need to install Composer. Luckily it’s as simple as running the following two commands:
The first command installs Composer into your local directory, the second will move the composer.phar file to a directory where it can be accessed globally by your system.
If you run the original command again you should see that Composer is installed and ready:
STEP 3: CLONE MAGENTO 2
To clone Magento CE 2 into your current directory run the Git following command:
It will clone the repo into a magento2 subdirectory, and this should take about 2-3 minutes depending on your broadband speed. Once it’s done run the following command to move into the Magento 2 root directory and checkout the master branch.
In order to work with Composer a project must have a composer.json file within its root directory. If you take a look at the file you’ll see a huge list of Magento 2 package dependencies. I’ve picked out first three