Install Magento 2 with Sample Data

Install Magento 2 with Sample Data

It is a step-by-step guide to installing Magento 2 via GitHub, setting up dependencies, and configuring the system. It covers database setup, admin user creation, and adding sample data for testing. This tutorial ensures a smooth installation process, making it easier for developers to explore and test Magento 2 with pre-loaded products and configurations.

You can install Magento in different ways. In this article, I will show you how to install Magento via GitHub.

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

Step 1: Clone Magento repository

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.

My document root folder location is – /home/vagrant/learning.portal/apps/magento2.blog.dev/public_html/src/web

So let’s clone the Magento repository in to the document root folder.

cd /home/vagrant/learning.portal/apps/magento2.blog.dev/public_html/src/web
git clone https://github.com/magento/magento2 .

Step 2: Update installation dependencies

To run Composer for the first time and install Magento packages, We need to run the following commend:

composer install

Step 3: Install Magento 2

Now it’s time to install Magento 2.

To install Magento 2, I am going to use Command Line Installer.

So, We need to run the following commend:

php -f bin/magento setup:install \
    --base-url=http://iyngaran.learning.magento2.blog.dev/ \
    --backend-frontname=admin \
    --db-host=localhost \
    --db-name=magento2_blog \
    --db-user=root \
    --db-password=root \
    --admin-firstname=Iyngaran \
    --admin-lastname=Iyathurai \
    --admin-email=hello@iyngaran.info \
    --admin-user=admin \
    --admin-password=iyngaran123 \
    --language=en_US \
    --currency=USD \
    --timezone=America/Chicago \
    --use-rewrites=1

Change your base-url, db-name, db-password, admin-email and admin-password to match your local setup.

If everything went correct, you are informed that the installation has been completed.

If your visit you local link through browser (http://iyngaran.learning.magento2.blog.dev/), Magento 2 should be installed and you will be able to see the home page.

Also you should be able access the backend via following url with the user name and password

http://iyngaran.learning.magento2.blog.dev/admin

Username : admin

Password : iyngaran123

Step 4: Install Sample Data

Create a new folder called ‘sample_data’ in the Magento installation directory (/home/vagrant/learning.portal/apps/magento2.blog.dev/public_html/src/web)

mkdir sample_data

Go into the sample_data folder.

cd sample_data

Then let’s clone the sample data from repository.

git clone https://github.com/magento/magento2-sample-data.git .

After deploying has been finished, run the following command.

php -f dev/tools/build-sample-data.php 
-- --ce-source="/home/vagrant/learning.portal/apps/magento2.blog.dev/public_html/src/web"

My Magento installation directory is : /home/vagrant/learning.portal/apps/magento2.blog.dev/public_html/src/web

So I am going to run the command as follows.

php -f dev/tools/build-sample-data.php 
-- —ce-source="/home/vagrant/learning.portal
/apps/magento2.blog.dev/public_html/src/web"

This will create symlinks to your Magento 2 installation.

After that, we need to set the ownership and permissions for the files and folders.

To set the ownership, let’s run the following command.

chown -R [new-owner]:[new-group] [directory-name-or-path]

In my web server, the new-owner name : vagrant and new-group name : vagrant. So I am going to run the command as follows.

chown -R vagrant:vagrant web

And then we need to set the folder permission. To do that, let’s go to the directory.

cd web

And run the following command to set permission to the folders.

find . -type d -exec chmod g+ws {} \;

Then let’s execute the following command to clear static files (cache).

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

And then we need to run the following two commands to install the sample data.

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

That’s it. Now you should have sample data installed. Now, If your visit you local link through browser (http://iyngaran.learning.magento2.blog.dev/), you should be able to see the pages with sample products, banners and etc.

Step 5: Set development mode to Magento

We need to remove the contents from following folders.

var/cache
var/di
var/generation
var/view_preprocessed
pub/static/frontend

Let’s run the following command to remove the contents from those folders.

rm -rf var/cache/* var/page_cache/* var/generation/* pub/static/frontend

We can run the following command to display the current mode.

php bin/magento deploy:mode:show

A message similar to the following displays:

Current application mode: default. (Note: Environment variables may override this value.)

Lets change to developer mode using the following command.

php bin/magento deploy:mode:set developer

Following is a summary of messages that display:

Enabled developer mode.

Thats it. Now, we have installed the magento2 and it is on developer mode. Now we can godhead and do the customization.

I hope you find this tutorial useful! 🙂