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
https://www.magentocommerce.com/download
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 https://getcomposer.org/doc/00-intro.md
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=https://repo.magento.com/ 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: https://github.com/magento/magento2 or you can download releases on https://github.com/magento/magento2/releases
Create empty directory and run:
git clone git@github.com:magento/magento2.git .
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-email=ivan.veres@inchoo.net --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 git@github.com:magento/magento2-sample-data.git
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: http://devdocs.magento.com/guides/v2.0/install-gde/bk-install-guide.html
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!
23 comments
Can’t we install or run the Magento 2.2 on our Windows machine with WAMP or XAMPP?
Please provide some details, as I have gone through the official documentation of Magento where they only mentioned about the Linux OS.
https://devdocs.magento.com/guides/v2.2/install-gde/install-flow-diagram.html
Thanks
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.
You need to upgrade PHP. Check your installed PHP version against the Magento Technology Stack Requirements (https://devdocs.magento.com/guides/v2.3/install-gde/system-requirements-tech.html) and pick one that is compatible. The each() function was deprecated as of PHP 7.2.0.
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!
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
I got blank page after installed sample data and run compile command
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!
Good guide Ivan!
For anyone who wants to install Magento 2 on Windows, you’ll want to follow this tutorial: https://www.simicart.com/blog/how-to-install-magento-2-localhost/?utm_source=quora&utm_medium=referral&utm_campaign=warroom
Very easy to follow, highly recommended!
What is the use of php bin/magento setup:di:compile ?
Why we need to run this command?
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,
Taras
If you use MAMP PRO (Mac or WIndows), you can enable Xdebug. It comes with the modules and functionality. You may need to follow a couple of tutorials to get it running and edit the conf file with the correct settings. I use PHP Storm and connect easily with Xdebug.
https://magenest.com/en/debug-magento-2-code-xdebug-phpstorm-1/
Why would you neglect to mention the command at “Install via Composer” to install the actual Magento 2?
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?
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.
I think everybody does at the moment. 🙂
Nice post , thanks Ivan Veres
Hi,
How to install without composer and github. ?
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.
thanks
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!
Would be nice to have a guide of how to speed up Magento for local development. 🙂
You may be memory limit issue. So use this instead for setup upgrades:
php -d memory_limit=-1 bin/magento setup:upgrade
php -d memory_limit=-1 bin/magento setup:di:compile
If you are looking for Magento2 Installation on MEMP stack, you can follow this article:
http://www.blog.magepsycho.com/magento-2-installation-on-memp-mac-os-x-nginx-mysql-php-fpm-stack/
Nice post Ivan.
You note using MySQL 5.7, but Magento 2 system requirements only not support for 5.6: http://devdocs.magento.com/guides/v2.0/install-gde/system-requirements.html
Have you run into any issues running M2 on MySQL 5.7?
Thanks
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.
Thanks