Installing Magento 2 with Composer

If you’re looking for something amusing to do some rainy afternoon, don’t install Magento 2. 😉

Before You Start

Before you start your installation, make sure your web server meets the minimum system requirements:

  • A Linux x86-64 operating system
  • 2GB of RAM
  • Composer (latest stable version)
  • Apache 2.2 or 2.4 with mod_rewrite enabled or nginx 1.8 or latest mainline version
  • MySQL 5.6 (MariaDB and Percona are compatible)
  • PHP 5.6x, 5.5.22 or higher, 7.02 up to 7.1.0 but not 7.0.5 – required PHP extensions:
    • bc-math
    • curl
    • gd, ImageMagick 6.3.7 or both
    • intl
    • mbstring
    • mcrypt
    • mhash
    • openssl
    • PDO/MySQL
    • SimpleXML
    • soap
    • xml
    • xsl
    • zip

For more information, see the magento dev docs.

Magento Access Keys

My Account
My Account Marketplace Tab – Click on My Access Keys link

Next, you need to log in to your account on the Magento Marketplace and request a key pair to authenticate the install with. It’s free. Sign up.

Your Magento Access Keys Screen
Your Magento Access Keys Screen

On the next screen, click the button to Create a New Access Key and give it any name you like. Leave this window open because you are going to need the Public Key and Private Key that it generates when you create a new access key.

For more information, see the magento dev docs.

Install Via Composer

In a terminal, on the command line, in the root of your magento 2 directory, enter the following:

composer create-project --repository-url= magento/project-community-edition

It is going to prompt you for a username. Enter the Public Key you got from the Magento Marketplace. It will prompt you for a password. Enter the Private Key you got from the Magento Marketplace.

Install Via Composer
Install Via Composer

Install Sample Data

Enter the following two commands in the terminal from your magento2 root directory:

php bin/magento sampledata:deploy
php bin/magento setup:upgrade

If you are really, really inordinately lucky, you now have a working magento 2 site with sample data installed. Most likely, though, you got some errors when you tried to install the sample data, and you’re stuck.

If you try to install sample data, and get a list of packages that “could not be found in any version,” don’t panic, there’s a GIT work around.

Install Sample Data via Git

Since the above method rarely works for anyone, there is a way to install the sample data from github. Create a directory anywhere outside your web root and clone the GitHub repo using this command:

git clone
Clone the repo
Clone the repo

Next, run the installer script

php -f /dev/tools/build-sample-data.php -- --ce-source="/var/www/"

After that finishes, go to your magento root, and run the updater:

bin/magento setup:upgrade

and you will see the sample data start to be installed. This process will take quite a while.

Almost Finished

Clear the cache (and fix file permissions if needed) and you should see all the sample data in the front and back ends now.
Again, if you’re lucky, your store is ready to rock and roll.
You might have an issue where your css files are not loading.

CSS is missing
CSS is missing

From your web root, recreate the static content:

php bin/magento setup:static-content:deploy

Then, reindex

php bin/magento indexer:reindex
Reindexing Magento
Reindexing Magento

Check that the folder permissions are 755 in the pub folder and its subfolders and delete all the files and folders in var/cache, var/page_cache, and var/sessions and go reload your site.

Magento 2 Sample Data
Magento 2 Sample Data

Leave a Reply

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