Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Magento 2 Cookbook
Magento 2 Cookbook

Magento 2 Cookbook: Exploring Magento 2 in the form of recipes

eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Magento 2 Cookbook

Chapter 2. Magento 2 System Tools

In this chapter, we will cover the basic tasks related to managing the system tools of Magento 2. You will learn the following recipes:

  • Installing Magento 2 sample data via GUI
  • Installing Magento 2 sample data via the command line
  • Managing Magento 2 indexes via the command line
  • Managing Magento 2 cache via the command line
  • Managing Magento 2 backup via the command line
  • Managing Magento 2 set mode (MAGE_MODE)
  • Transferring your Magento 1 database to Magento 2

Introduction

This chapter explains how to install and manage Magento 2 on a production-like environment. We will be installing a new Magento 2 instance via the shell command with and without sample data. Besides the setup, managing Magento 2 is different from the current Magento version. We will be using a lot of tools from the command line so basic shell knowledge is advised. The command-line tool in the /bin directory is similar to the current Swiss army knife tool in the current Magento version known as n98-magerun.

Using bin/magento and Composer is one of the new key features in Magento 2 that will rock your world.

The recipes in this chapter will focus primarily on a more advanced setup of how to install Magento 2 and manage it. However, in some situations, we will dive in deeper related to the subject.

Here is an overview of all the command-line tools in Magento 2:

root@mage2cookbook:/var/www/html# bin/magento
Magento CLI version 2.0.0

Usage:
 command [options] [arguments]

Options...

Installing Magento 2 sample data via GUI

Installing Magento 2 via the graphical user interface (GUI) is not new. We have already done this in Chapter 1, Installing Magento 2 on Apache and NGINX. Now, we will be installing a new clean version including the sample data.

The sample data can be installed during and at the end of the procedure. We will be using a composer.json file for our setup prerequisites. First, we will be installing a clean version with sample data, and later, I will show you how to install it at the end in case you already have a preinstalled version.

Getting ready

For this recipe, we will use a Droplet created in Chapter 1, Installing Magento 2 on Apache and NGINX, at DigitalOcean, https://www.digitalocean.com/. We will be using NGINX, PHP-FPM, and a Composer-based setup. No other prerequisites are required.

How to do it...

For the first step, you can either create a new Droplet or rebuild a clean Droplet based on a Ubuntu or RedHat DigitalOcean image.

The option to rebuild...

Installing Magento 2 sample data via the command line

Installing Magento 2 via the shell is not new. In the current Magento version, it was already possible using the install.php file. The configuration looked like this:

/usr/local/bin/php -f install.php -- \
--license_agreement_accepted "yes" \
--locale "en_US" \
--timezone "America/Los_Angeles" \
--default_currency "USD" \
--db_host "mysql.example.com" \
--db_name "your_db_name" \
--db_user "your_db_username" \
--db_pass "your_db_password" \
--db_prefix "" \
--admin_frontname "admin" \
--url "http://www.examplesite.com/store" \
--use_rewrites "yes" \
--use_secure "no" \
--secure_base_url "" \
--use_secure_admin "no" \
--admin_firstname "your_first_name" \
--admin_lastname "your_last_name" \
--admin_email "your_email@example.com" \
--admin_username "your_admin_username...

Managing Magento 2 indexes via the command line

In the current version of Magento, using indexes is one of the most important key features. Without the correct indexes, we will not be able to use Magento properly.

What do the indexes do, and why are they so important? One of the key elements is to make things run faster. Without indexing, Magento 2 would have to calculate data on the fly. In Magento 2, we will be using the following nine indexes:

  • Customer Grid: This indexer rebuilds the customer's grid. This is a new indexer in Magento 2 for optimized rendering of the adminhtml backend pages.
  • Category Products: This indexer creates the association between categories and products based on the associations that you set in the backend on the categories and relates to the Product Categories indexer. The flat catalog indexer creates a flat optimized table in the database.
  • Product Categories: This indexer creates the association between products and categories based on the associations that...

Managing Magento 2 cache via the command line

Cache management is one of the new optimized key features in Magento 2. We will be using the following cache types:

Cache types

Cache type code name

Description

Configuration

config

Magento collects configuration from all modules, merges it, and saves the merged result to the cache. This cache also contains store-specific settings stored in the filesystem and database.

Clean or flush this cache type after modifying configuration files.

Layout

layout

This is the compiled page layout (that is, the layout components from all components).

Clean or flush this cache type after modifying layout files.

Block HTML output

block_html

This is the HTML page fragments per block.

Clean or flush this cache type after modifying the view layer.

Collections data

collections

This is the result of database queries.

If necessary, Magento cleans up this cache automatically, but third-party developers can put any data in any segment of the cache.

Clean...

Managing Magento 2 backup via the command line

Every production environment needs a proper backup plan. By default, Magento 2 has a complete set of options to create and roll back backups.

When creating a backup, we can use one of the following options:

Option

Meaning

Backup file name

--code

This creates a backup from the filesystem (excluding /var and /pub/static

var/backups/<timestamp>_filesystem.tgz

--media

This creates a backup from the /media directory

var/backups/<timestamp>_filesystem_media.tgz

-db

This creates a backup from the current database

var/backups/<timestamp>_db.gz

Tip

Besides the Magento backup options, it is always advisable to use an alternative backup solution connected to a backup storage.

Getting ready

When creating a backup, Magento will store it in the var/backups directory. In this recipe, we will refer to the bin/magento setup:backup and bin/magento setup:rollback options.

How to do it...

For the purpose of this recipe, let's assume...

Introduction


This chapter explains how to install and manage Magento 2 on a production-like environment. We will be installing a new Magento 2 instance via the shell command with and without sample data. Besides the setup, managing Magento 2 is different from the current Magento version. We will be using a lot of tools from the command line so basic shell knowledge is advised. The command-line tool in the /bin directory is similar to the current Swiss army knife tool in the current Magento version known as n98-magerun.

Using bin/magento and Composer is one of the new key features in Magento 2 that will rock your world.

The recipes in this chapter will focus primarily on a more advanced setup of how to install Magento 2 and manage it. However, in some situations, we will dive in deeper related to the subject.

Here is an overview of all the command-line tools in Magento 2:

root@mage2cookbook:/var/www/html# bin/magento
Magento CLI version 2.0.0

Usage:
 command [options] [arguments]

Options...

Installing Magento 2 sample data via GUI


Installing Magento 2 via the graphical user interface (GUI) is not new. We have already done this in Chapter 1, Installing Magento 2 on Apache and NGINX. Now, we will be installing a new clean version including the sample data.

The sample data can be installed during and at the end of the procedure. We will be using a composer.json file for our setup prerequisites. First, we will be installing a clean version with sample data, and later, I will show you how to install it at the end in case you already have a preinstalled version.

Getting ready

For this recipe, we will use a Droplet created in Chapter 1, Installing Magento 2 on Apache and NGINX, at DigitalOcean, https://www.digitalocean.com/. We will be using NGINX, PHP-FPM, and a Composer-based setup. No other prerequisites are required.

How to do it...

For the first step, you can either create a new Droplet or rebuild a clean Droplet based on a Ubuntu or RedHat DigitalOcean image.

The option to rebuild...

Left arrow icon Right arrow icon

Key benefits

  • Take advantage of the latest features in Magento 2 to set up an e-commerce store that fits your business needs
  • Packed with several advanced recipes, not just to manage your online store, but to extend and design it as well
  • Written in a cookbook style, you can pick and choose your recipe to carry out your day- to- day Magento store tasks

Description

Magento 2 is an open source e-commerce platform that has all the functionality to function from small to large online stores. It is preferred by developers and merchants due to its new architecture, which makes it possible to extend the functionalities with plugins, a lot of which are now created by the community. This merchant and developer guide is packed with recipes that cover all aspects of Magento 2. The recipes start with simple how-to’s then delve into more advanced topics as the book progresses. We start with the basics of setting up a Magento 2 project on Apache or Nginx. Next, you will learn about basics including system tools and caching to get your Magento 2 system ready for the real work. We move on to simple tasks such as managing your store and catalog configuration. When you are familiar with this, we cover more complex features such as module and extension development. Then we will jump to the final part: advanced Magento 2 extensions. By the end of this book, you’ll be competent with all the development phases of Magento 2 and its most common elements.

Who is this book for?

The book is for existing Magento users who want to gain further expertise and insights into managing, designing, and extending their online store in Magento to fit their business needs. Working knowledge of Magento and basic familiarity with programming is expected.

What you will learn

  • Set up a Magento 2 project on Apache or Nginx.
  • Transfer your Magento 1 database to Magento 2 using the Magento 2 system tools.
  • Boost the performance of Magento 2 by enabling different types of caching.
  • Build a Magento 2 multi-store by creating a root catalog, subdirectories, and products.
  • Create and manage pages, blocks, and front-end apps.
  • Manage your Magento store by setting up the correct TAX rules.
  • Design custom themes within the Magento 2 framework.
  • Create basic and advanced extensions using Magento 2.
Estimated delivery fee Deliver to Ireland

Premium delivery 7 - 10 business days

€23.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 28, 2016
Length: 342 pages
Edition : 1st
Language : English
ISBN-13 : 9781785887062
Vendor :
Magento
Languages :
Concepts :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Estimated delivery fee Deliver to Ireland

Premium delivery 7 - 10 business days

€23.95
(Includes tracking information)

Product Details

Publication date : Mar 28, 2016
Length: 342 pages
Edition : 1st
Language : English
ISBN-13 : 9781785887062
Vendor :
Magento
Languages :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 110.97
Magento 2 Cookbook
€36.99
Magento 2 Development Cookbook
€41.99
Magento 2 Developer's Guide
€31.99
Total 110.97 Stars icon

Table of Contents

9 Chapters
1. Installing Magento 2 on Apache and NGINX Chevron down icon Chevron up icon
2. Magento 2 System Tools Chevron down icon Chevron up icon
3. Enabling Performance in Magento 2 Chevron down icon Chevron up icon
4. Creating Catalogs and Categories Chevron down icon Chevron up icon
5. Managing Your Store Chevron down icon Chevron up icon
6. Creating a Magento 2 Theme Chevron down icon Chevron up icon
7. Creating Magento 2 Extensions – the Basics Chevron down icon Chevron up icon
8. Creating Magento 2 Extensions – Advanced Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(1 Ratings)
5 star 0%
4 star 100%
3 star 0%
2 star 0%
1 star 0%
Noph Veluvan Jul 07, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Good to have if you want to develop your own code. I am still new to it.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela