Home » Magento, Magento 23 October 2016

Magento 2: Install via Composer and Command Line (CLI)

This article/tutorial show how to download and install Magento 2 through command line interface (CLI). We will be using Composer to download Magento 2 from Magento’s repository.

Here is the step-by-step guide on installing Magento 2 via command line:

1) Check & Verify System Requirements

Before, downloading and installing Magento 2, we need to make sure that our system/computer meets all the system requirements in order to run Magento 2. System requirements means proper PHP version and required PHP modules, proper database, web server, etc. Check Magento 2 system requirements: http://devdocs.magento.com/guides/v2.0/install-gde/system-requirements.html

2) Install Composer

Make sure you have composer installed in your system. You can get composer from: http://getcomposer.org

Alternatively, you can install composer in Ubuntu Linux using the following command:

3) Download Magento via Composer

In Ubuntu 16.04 Linux, the webserver root is at path /var/www/html. I will create a folder named magento2 inside it and download Magento 2 over there. So, the full path for my magento 2 folder will be /var/www/html/magento2.

Using Composer, get/download Magento CE edition to your computer:

After running this command, it will ask for username and password for repo.magento.com.

To get the username and password for repo.magento.com, you have to generate access keys from https://marketplace.magento.com/customer/account/

– Go to https://marketplace.magento.com/customer/account/
– Login
– After you are logged in, click My Access Keys link
– On My Access Keys page, click on Generate Keys button
– Then, you will see two keys (Public and Private)
– Public Key will be your username
– Private Key will be your password

4) Set proper file permissions

You have to set write permissions to vendor, app/etc, pub/static, pub/media, and var directories. You can set the permission to all of these folders with the following command:

5) Switch User

Switch to user which has write permission to your magento2 directory.

In Ubuntu, my default user has sudo priviledge and is the owner of the /var/www/html/magento2 directory. So, I didn’t have to switch user.

6) Install Magento 2

Go to your magento2 web root directory:

As you can see below, I have specified the base url, database host, database user, database password, admin name, admin email, admin password, default currency, default timezone, etc. You can update them with your data.

After installation completion, you will get the message something like this:

So, in this case, our Magento 2 admin URL is http://127.0.0.1/magento2/admin_1vdc5o

Note: You need to give write permission to pub and var directory if you get cache write permission error:

7) Install Sample Data (Optional)

This step is optional. You have a clean Magento 2 installed. Now, if you also need to install the sample products, categories, orders, customers, etc. then you need to install sample data.

Go to your magento2 web root directory:

Run the following command:

You might again be asked the username and password for repo.magento.com

To get the username and password, you need to do the following:

– Login to https://marketplace.magento.com/customer/account/
– Go to My Access Keys page
– Generate Keys
– Then, you will see two keys (Public and Private)
– Public Key will be your username
– Private Key will be your password

After sample data has been installed, you have to clean cache and run setup upgrade:

You will get the following message after successful setup upgrade:

You may ignore this command for development mode because Magento automatically compiles the files on first page load. If you want to go into production mode, then you need to run the following command to compile files:

Note: Now, when you browse your Magento site, if you get error regarding permission issue while storing cache then you have to give write permission to pub and var directories:

That’s all. Now, you should be able to see the categories and products in frontend when you browse http://127.0.0.1/magento2.

Hope this helps. Thanks.

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed

Comments are closed.