How to install Magento 2

How to install Magento 2

When installing Magento 2 on your machine you should ask yourself:

  • Do I need more problems in my life?

If the answer is Yes, continue reading.

I’ll be installing Magento 2 on my dev machine – Linux Ubuntu 16.04 with

  • Php 7.0.7
  • Mysql 5.7.12
  • Composer 1.1.2

Before continuing, make sure you have all the prerequisites, required for running Magento 2.

I set up one virtual host, to rule them all! That way all my Magento 2 installations will be found by this local link http://m2.loc/2.07/ for you to follow along.

As you may, or may not already know, there are a few ways to install it. I will go through each installation, with and without sample data.

Install from archive file

First and easiest way is to download it from Magento download page

You can choose from few different archive types (zip, tar.gz, tar.bz2) , with and without sample data.
Magento was kind enough to pack with all composer dependencies in the archive, so you don’t have to run Composer.

In this installation Magento core code is stored under /vendor directory and updating is possible through Magento admin.

So next steps are easy, just visit http://m2.loc//2.07/magento-website/ (in my case) and follow Setup Wizard.

Install via Composer

Second, but not the last, is installing Magento via composer. Composer is a tool for dependency management in PHP. To learn more visit this link

In this installation, Magento core code is also stored under /vendor directory and updating is possible through Magento admin.

First you need authentication keys which can be obtained here, and you will need Magento account to login.
Once logged in, go to “My Access Keys”, enter some descriptive “Name” and generate new set of keys. Magento uses this approach because, in future, extensions you buy from marketplace, will be available to you, through Magento admin interface.

Enter this command in terminal:

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

When prompted, your public key is username, and private key is password.

After that, Magento is ready for installation. Go through Setup Wizard and install it.

This was without sample data. So to install sample data, navigate to your Magento 2 root directory through terminal, and run the following command:

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

These two commands will update your composer.json file and install sample data. If you get this message, after installing sample data – “Please re-run Magento compile command”, enter the following in terminal:

php bin/magento setup:di:compile

This command will take some time to complete.

Install via GitHub

Third, and the last one, is cloning or downloading release from GitHub repository.
In this installation, I will show you how to avoid setup wizard and install Magento through terminal. But, it is important to mention that in this installation Magento core code is stored under app/code not in vendor/ like in previous two examples.
When you try to update Magento through Admin interface, you will get error that this is a GitHub version and it’s not possible to update. GitHub releases are intended to be used by contributors/developers.

First we must clone Magento repo from here: or you can download releases on

Create empty directory and run:

git clone .

After deploying has been finished, run:

composer install

Now it’s time to install Magento 2. My setup looks like this:

php -f bin/magento setup:install –base-url=http://m2.loc/2.07/github/ --backend-frontname=admin
--db-host=localhost --db-name=m2git --db-user=root --db-password=inchoo --admin-firstname=Magento
--admin-lastname=User --admin-user=admin --admin-password=magento123
--language=en_US --currency=USD --timezone=America/Chicago –use-rewrites=1

Change your base-url, db-name, db-password, admin-email, admin-password to match your local setup.
If your visit you local link through browser (http://m2.loc/2.07/github/), Magento 2 should be installed.

If you need sample data, follow along.
In your web root (not magento2) run:

git clone

Navigate into cloned directory and execute:

php -f dev/tools/build-sample-data.php -- --ce-source="your Magento CE install dir"

This will create symlinks to your Magento 2 installation.
Set ownership and permissions if you are on Linux machine:

chown -R :your web server group name
find . -type d -exec chmod g+ws {} \;

Then you need to clear static files (cache).
Navigate to Magento 2 var/ folder and enter following:

rm -rf cache/* page_cache/* generation/*

In Magento 2 documentation there are no further instructions. However you need to install sample data.

php bin/magento setup:upgrade
php bin/magento setup:di:compile

After that you should have sample data installed.

If you have some problems reference at:

If this or anything else regarding Magento development confuses you, we will gladly check out your site and offer technical insights on what to improve based on our detailed custom report. Feel free to get in touch!

Related Inchoo Services

You made it all the way down here so you must have enjoyed this post! You may also like:

3 best open-source eCommerce platforms in 2021 Zrinka Antolovic
Zrinka Antolovic, | 8

3 best open-source eCommerce platforms in 2021

Ready for 2nd Meet Magento Croatia with agenda focused on PWA? Book the dates! Maja Kardum
Maja Kardum, | 0

Ready for 2nd Meet Magento Croatia with agenda focused on PWA? Book the dates!

We’ve developed a Croatian Language Pack for Magento 2 Maja Kardum
Maja Kardum, | 4

We’ve developed a Croatian Language Pack for Magento 2


  1. sir when i m open magento in browser so this erro ”
    Deprecated: The each() function is deprecated. This message will be suppressed on further calls in C:\xampp\apps\magento\htdocs\vendor\colinmollenhour\cache-backend-file\File.php on line 81
    There has been an error processing your request
    Exception printing is disabled by default for security reasons.

    Error log record number: 1317850547 “.
    xampp version 3.2.2.
    plz tell me solution.

  2. Don’t using this stupid system, I am using a prestashop, All I need – just upload on server, all next steps to install prestashop will be understand for 99% population of planet earth..

    Magento – it is a TRASH!

    1. Magento is not a shit i migrate from prestashop to magento and the benefit increase of 200%, prestashop is for kids who not know nothing of server

  3. I’ve edited your text and amended with all the necessary info, but terminal replies with my password in this message;

    -bash: (my pass): event not found

    Any idea why this would be- seems like a straightforward setup, but typical it fails!

  4. Hi, Ivan.

    Thank you for this article.
    I have tried magento dev box for magento 2 installation and it is great. It is easy to use it and it is quite fast.
    Only one thing I am missing with it – xdebug. How to develop without debugging? May be it is possible, but I haven’t found yet.
    Could you please add this way of installation to this article and don’t forget about xdebug)

    Thank you in advance,

  5. Why would you neglect to mention the command at “Install via Composer” to install the actual Magento 2?

  6. Composer gives error (due to permissions probably).
    I’m running it from my own user instead of root on ubuntu 14.
    Whats the solution if i want to run composer with my current user.
    Have you tried it?

  7. Hey Ivan,

    Do you have any article on how to move an existing magento 2 store to another server? I see lots of problems while doing that.

  8. Hi Ivan,

    this is the message that I see after the github installation: Magento supports PHP 5.6, 7.0.2, and 7.0.6 or later.


  9. Thank you very much Ivan, Its worked.

    I have followed so-many tutorials and even magento articles too but nothing helped effectively but this one really helped no issues I used Composer installation and sample data as-well.

    I think recently there are some slice changes are released by magento for install process so some-of old installing tutorials/articles not works well.

    Again Thanks for your effort!

    1. Hi John,

      I’m running M2 on MySQL 5.7 for a few months now and so far I didn’t run into any issue.


Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.