How to install Magento 2 on a Developer Machine

Let’s tackle the right way to install Magento 2 on your development environment. Magento recently released their latest version ‘Magento 2.0’ in the mid of November 2015. Magento Team was working on this version from last 6 years & finally we can see a public release now. Until then I was using 1.9.x.x versions of Magento, so it was a good time for me to dive in with Magento 2.

For this tutorial I am using a Ubuntu 14.04 machine with following prerequisites. The purpose of using a Ubuntu machine for this tutorial is that, you can follow these instructions on a Cloud Server or a Vagrant Machine. To set up LAMP on your server you can follow my guide “How to set up LAMP on Ubuntu 14.04“.

Magento 2 Prerequisites

  1. A LAMP environment (Windows users can use Ammps).
  2. Composer (http://getcomposer.org).
  3. Git installed your system (http://git-scm.com).
  4. A GitHub Account (http://github.com).
  5. A Magento Connect Account (https://www.magentocommerce.com/magento-connect/).

LAMP Configuration

Magento 2 requires Apache 2.2 or 2.4, PHP 5.5 or later(You can also use  PHP7) & MySQL 5.6 or later version on your system. Before we start the Magento installation, we will need to set up some required PHP extensions. such as php5-mcrypt, php5-xsl & php5-intl (You can find more information about System Requirement on Magento Devdocs).

sudo apt-get install php5-mcrypt php5-xsl php-intl

And don’t forget to enable these extensions by using this command:

sudo php5enmod mcrypt

Also make sure that you have enabled mod_rewrite module in Apache configuration.

sudo a2enmod rewrite

Installing Composer

Composer is php dependency manager, which will help you to manage php libraries for your project. In the modern era of web development, Composer is very essential & useful tool for a PHP developer. To install composer on your system, simple follow these commands:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Installing Git

Git is version control for your projects. If you are not using git for your projects yet, then I highly recommend you to start using git your development workflow. To learn git in your browser please head over to http://try.github.com.

Install git on your system using this command. Windows/Mac users can grab installer from https://git-scm.com/.

sudo apt-get install git

Magento 2 Installation

Now that we have prepared our system with prerequisites, it’s time to proceed for Magento 2 installation! But before we proceed for installation let’s create free account for yourself on both Github & Magento Connect. We will need Personal access token from Github & Authentication tokens (Secure Keys) from Magento Connect account.

Obtain Personal access token from Github

To obtain personal access token from Github, logged in to your Github account and find Personal access tokens on Settings page.

Github - Personal access tokens

after generating token, save it in secure place, we will need this token at the time of cloning the Magento repository.

Grab Authentication keys(Secure keys) from Magento Connect

Our next step is to grab Authentication tokens from Magento Connect. You can find these under Developers area with the section named Secure Keys.

Magento Connect Secure Keys for Magento 2 Installation

We will use public key as username and private key as password while installing Magento in the next step.

Proceed for Magento 2 Installation

All right! We are finally ready for the installation. Open a terminal window in your project folder. In my case I have my project folder at ‘/var/www’. I have already created an alias of ‘http://magento.dev’ pointing to the ‘/var/www/magento2′ directory. So to clone the Magento’s master repository into our project folder enter this command in the terminal:

git clone -b 2.0 https://github.com/magento/magento2

After this process is finished, change working directory to /var/www/magento.

cd /var/www/magento2

Then run composer install.

composer install

Not it will ask you for the username & password. Use public key as username and private key as password from Magento Connect.

It will also prompt you for Github auth token to go over the API rate limit. Just enter the token you grabbed from Github.

Installing Magento 2 Sample Data

You can also install sample data for Magento setup. Which is useful while Magento development.

php bin/magento sampledata:deploy

So now we have grabbed all the necessary files for Magento Installation. Our next step is to install Magento. We can install Magento by using two ways, one is using setup wizard & other is command line.

Create Database

We will need a database for installation. I have created a sample database with these credentials

  • DB name : magento
  • DB user : root
  • DB password : password

Magento 2 Installation (using Setup Wizard)

To install Magento using setup wizard, follow these steps:

  1. Open your favourite browser.
  2. Enter this url. ‘http://magento.dev/setup/’.
  3. Agree to Setup Magento & Follow the instructions.

Magento 2 Installation (using Command line)

You can also install Magento using command line. I have prepared a sample command to install magento in one step.

I have defined these options in command line:

  • DB name : magento
  • DB user : root
  • DB password : password
  • Admin First Name : Magento
  • Admin Last Name : User
  • Admin Email : [email protected]
  • Admin User : admin
  • Admin Password : admin123
  • Language : en_US
  • Currency : USD
  • Timezone : America/Chicago
  • Url Rewrite Option as : 1
php bin/magento setup:install --base-url=http://magento.dev/ \--db-host=localhost --db-name=magento --db-user=root --db-password=password \--admin-firstname=Magento --admin-lastname=User [email protected] \--admin-user=admin --admin-password=admin123 --language=en_US \--currency=USD --timezone=America/Chicago --use-rewrites=1

Conclusion

So that was my first tutorial on Magento 2. Let me know if you have any in comments below. In upcoming weeks I try to will bring more tutorials on Magento 2. In fact… I am planning to dedicate my entire blog to Magento 2 Development. So if you have any suggestion please let me know, I will try my best to help you out. See you next week, Bye!

  • Delwar Hossain

    I have run the command apt-get install php5-mcrypt php5-xsl php-intl
    i shows
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package php-intl

    What should i do?

  • Dushyant Joshi

    Hi thanks for the tutorial. By following this I have got Magento
    ver. 2.0.13 but this is not the latest. How do I get the latest one. Thanks.