Bash Script: Easily Backup your Magento2 Code Files + Database

October 2, 2017  |  No Comments  |  by Raj (MagePsycho)  |  Linux, Mac OS-X, Magento 2

We had created a similar Backup Script for Magento1 in the past. Now we are back with the much-improvised version for Magento2.
You must be wondering why we needed a bash script for Magento2 backup even it comes up with inbuilt console command:

php /path/to/magento2/bin/magento setup:backup -v --code --media --db

Some of the reasons are:

  • Linux native command is always faster than PHP.
  • There is no enabling and disabling of maintenance mode while running the backup script. So there is no any downtime.
  • To have more Freedom. Magento2 console script is limited. What if you want to backup in Amazon S3, Google Drive etc.? If you have independent script you can play as you like without worrying about breaking the Magento2 system.

You can find the full script below:

Please visit our GitHub project page for more info: MagePsycho/magento2-db-code-backup-bash-script


You can simply download the script file and give the executable permission.
In Linux system this can be simply done as:

cd /path/to/your/preferred/download/folder
curl -O
chmod +x

If you want to make this command system-wide then

sudo mv /usr/local/bin/


To display help

./ --help


To backup database only

./ --type=db --src-dir=/path/to/magento2/root --dest-dir=/path/to/destination

To backup code only

./ --type=code --skip-media=1 --src-dir=/path/to/magento2/root --dest-dir=/path/to/destination

To backup code + database

./ --type=all --skip-media=1 --src-dir=/path/to/magento2/root --dest-dir=/path/to/destination

To schedule backup via Cron
You can run this command manually (on demand) or via cron.
If you want to schedule via Cron, just add the following line in your Crontab entry (crontab -e)

0 0 * * * /path/to/ --type=all --skip-media=1 --src-dir=/path/to/magento2/root --dest-dir=/path/to/destination > /dev/null 2>&1

0 0 * * * expression means the command will run run at every midnight. You can refer to to know more about the cron-expression.

Hope you will find this script useful in your day-to-day operation. Any issues found can be raised at our GitHub project – Bash Script: Backup Magento2 Code + Database

Let us know your experience/feedback on this script.

Best Resources to Help You Learn Magento

August 29, 2017  |  1 Comments  |  by Raj (MagePsycho)  |  Magento, Magento 2

Learning Magento may seem like a laborious task at first, but when you know the right
resources and the right places to head to, it may not be that difficult to master the platform.
Magento is one of the biggest e-commerce platforms and it powers some of the biggest websites
on the internet. Even small e-commerce stores prefer to base their online stores on Magento and
it’s an understatement to say that it’s just popular. Hence, if you are looking forward to starting
learning the platform and start a development career, you are on the right path!
Now let’s look into the best Magento resources on the internet that will help you in your
endeavor to master Magento and step into the world of e-commerce with confidence.

Official Magento Documentations

While we are on the subject of learning Magento, the Official Magento Documentation needs no introduction. Since it comes directly from the Magento labs, it’s the surest way to learn and know your way around Magento without losing focus. While there are several other resources that can help you up your development game, the official document takes the lead by default!

Head over to the official documentation if you are looking for a direct source of Magento knowledge!

Alan Storm

If there is one person who stands out and makes a significant impact in the Magento Community, it’s Alan Storm. Alan is a programmer who makes things easier for anyone who has a hard time understanding code! His professional web blog of the same name is a trusted source of how-to’s and if you are looking forward to learning from a professional, look no further than Alan Storm.

The blog is not limited to just Magento, though, and there’s a lot you can look forward to if you are new to the coding business!

Inchoo’s Blog

Inchoo is one of the leading Magento-based software developers. Founded in 2008, Inchoo is well-known for its blog, which is a great source for insight into Magento development. Among all the blogs based on Magento, Inchoo is among the ones that maintain quality and aims to teach and educate the readers than just producing articles for the sake of it.

If you are here to learn Magento and improve your understanding, head over to Inchoo’s blog to get some serious knowledge.


Magenticians, as suggested by the name, is a dedicated Magento blog and one of the fastest growing blogs in the industry. With a tagline that says ‘Magento Made Easy’, Magenticians is a great pool of resource to help ease your Magento journey with regular how-tos, tutorials, e-commerce articles, and interviews with Magento Influencers etc., to keep you up to date with all things Magento.

From all the resources available, Magenticians is the most regular in posting quality content and Muneeb Ul Hasan’s tutorials are on-point and worth looking into!

MagePsycho’s Magento Blog

The MagePsycho’s blog is another useful resource with a roster of several experts and Magento developers. Not only does the blog give you great tutorials, but you can stay up to date with all the latest industry news and happenings!

Don’t forget to check out Raj KB’s tutorials and guides, as they are always insightful and bring something new to the table!

Note: More list will be added soon.


There are hundreds of other blogs in the blogosphere that publish Magento related content, but there are factors that allow some to lead the way and are considered the best among the rest. And that is why we go through the necessary research and sieve out the best ones for you. We’ve listed the ones we think are necessary for anyone jumping into the Magento world, but if you feel that there is some blog that deserves a mention in this list, let us know in the comments below and we’ll check it out!

Create Custom Shipping Module in Magento 2

November 25, 2015  |  16 Comments  |  by Raj (MagePsycho)  |  Magento 2

As you know Magento 2 GA is already released on mid of November, 2015. Now the development of Magento 2 components is taking by storm and the developers are especially busy with porting their popular Magento 1 extensions.

In ours case, We are already into Magento 2 development: busy porting some of our popular Magento 1 Extensions and side by side learning new concepts introduced by Magento 2.

In this tutorial we will learn how to create a custom shipping module in Magento2 which is fairly easy as compared to CRUD & Payment modules.

Namespace = MagePsycho
Module = Customshipping

Custom Shipping Module Development

1. Register the module
File: app/code/MagePsycho/Customshipping/etc/module.xml

<?xml version="1.0"?>
 * @category   MagePsycho
 * @package    MagePsycho_Customshipping
 * @author
 * @website
 * @license  Open Software License (OSL 3.0)
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="MagePsycho_Customshipping" setup_version="1.0.0">

2. Add System Configuration Settings
File: app/code/MagePsycho/Customshipping/etc/adminhtml/system.xml

<?xml version="1.0"?>
 * @category   MagePsycho
 * @package    MagePsycho_Customshipping
 * @author
 * @website
 * @license  Open Software License (OSL 3.0)
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="../../../../Magento/Config/etc/system_file.xsd">
        <section id="carriers" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
            <group id="magepsycho_customshipping" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Custom Shipping</label>               
                <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">
                <field id="title" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                <field id="name" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Method Name</label>
                <field id="price" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Shipping Cost</label>
                    <validate>validate-number validate-zero-or-greater</validate>
                <field id="specificerrmsg" translate="label" type="textarea" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Displayed Error Message</label>
                <field id="sallowspecific" translate="label" type="select" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Ship to Applicable Countries</label>
                <field id="specificcountry" translate="label" type="multiselect" sortOrder="91" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Ship to Specific Countries</label>
                <field id="showmethod" translate="label" type="select" sortOrder="92" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Show Method if Not Applicable</label>
                <field id="sort_order" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Sort Order</label>

3. Define shipping carrier model
File: app/code/MagePsycho/Customshipping/etc/config.xml

<?xml version="1.0"?>
 * @category   MagePsycho
 * @package    MagePsycho_Customshipping
 * @author
 * @website
 * @license  Open Software License (OSL 3.0)
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="../../../Magento/Store/etc/config.xsd">
                <title>Custom Shipping</title>
                <specificerrmsg>This shipping method is not available. To use this shipping method, please contact us.</specificerrmsg>

Notes: ‘config/default/carriers/model’ node is used to define Model class for Custom Shipping which will be responsible for handling the Shipping Charges.
In fact this file is also used to set default values for Shipping Settings.

4. Create shipping carrier model class
File: app/code/MagePsycho/Customshipping/Model/Carrier/Customshipping.php


namespace MagePsycho\Customshipping\Model\Carrier;

use Magento\Quote\Model\Quote\Address\RateRequest;

 * @category   MagePsycho
 * @package    MagePsycho_Customshipping
 * @author
 * @website
 * @license  Open Software License (OSL 3.0)
class Customshipping extends \Magento\Shipping\Model\Carrier\AbstractCarrier implements
	 * @var string
	protected $_code = 'magepsycho_customshipping';

	 * @var bool
	protected $_isFixed = true;

	 * @var \Magento\Shipping\Model\Rate\ResultFactory
	protected $_rateResultFactory;

	 * @var \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory
	protected $_rateMethodFactory;

	 * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
	 * @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
	 * @param \Psr\Log\LoggerInterface $logger
	 * @param \Magento\Shipping\Model\Rate\ResultFactory $rateResultFactory
	 * @param \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory
	 * @param array $data
	public function __construct(
		\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
		\Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory,
		\Psr\Log\LoggerInterface $logger,
		\Magento\Shipping\Model\Rate\ResultFactory $rateResultFactory,
		\Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory,
		array $data = []
	) {
		$this->_rateResultFactory = $rateResultFactory;
		$this->_rateMethodFactory = $rateMethodFactory;
		parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);

	 * @param RateRequest $request
	 * @return \Magento\Shipping\Model\Rate\Result
	 * @SuppressWarnings(PHPMD.UnusedLocalVariable)
	public function collectRates(RateRequest $request)
		if (!$this->getConfigFlag('active')) {
			return false;

		/** @var \Magento\Shipping\Model\Rate\Result $result */
		$result = $this->_rateResultFactory->create();

		$shippingPrice = $this->getConfigData('price');

		$method = $this->_rateMethodFactory->create();




		return $result;

	 * Get allowed shipping methods
	 * @return array
	public function getAllowedMethods()
		return [$this->_code => $this->getConfigData('name')];

That’s all from development point of view.
Now you need to enable the module by running following series of commands(from root of your Magento 2 installation):

php bin/magento module:enable MagePsycho_Customshipping --clear-static-content
php bin/magento setup:upgrade

Go to the backend: System > Configuration > Sales > Shipping Methods > You will see new tab named ‘Custom Shipping’. And the settings looks like:

Magento 2 - Custom Shipping Method

Magento 2 – Custom Shipping Method

And the frontend looks like:

Magento2  - Custom Shipping at Checkout

Magento2 – Custom Shipping – Checkout

Magento2 - Custom Shipping - Checkout Summary

Magento2 – Custom Shipping – Checkout Summary

This module is available on GitHub.
In order to install the module from github:
Installation Using Composer

composer config repositories.magesycho-magento2-custom-shipping git
composer require magepsycho/magento2-custom-shipping:dev-master

Installation Using Zip
Download the zip file, extract & upload the files to path: app/code/MagePsycho/Customshipping/

After installation, don’t forget to enable the Module as described above.

Please do comment below if you have any queries regarding Shipping Module development in Magento 2.
Happy Magento 2 Coding!

Install Magento 2 module from github or bitbucket repository using composer

October 30, 2015  |  No Comments  |  by Raj (MagePsycho)  |  Magento 2

In previous article, we discussed about How to install Magento 2 on MEMP (Mac OS X + Nginx + MySQL + PHP-FPM) stack using Composer

In this article we will discuss on How to install Magento 2 modules from any github or bitbucket repositories.

Let’s say we have Easy Template Path Hints (a Magento 2 module used for triggering the template path hints on the fly) on github.

Install Module

In order to install the Easy Template Path Hints Module from Github, run the following commands:

composer config repositories.magesycho-magento2-easy-template-path-hints git
composer require magepsycho/magento2-easy-template-path-hints:dev-master


1. Registering the module git repository

composer config repositories.magesycho-magento2-easy-template-path-hints git

Composer config repository command syntax:

composer config repositories.<unique-repo-name> <vcs-type> <vcs-url-https-or-sshl>

Composer will register a new repository to composer.json (under “repositories” node). Updated composer.json looks like:

  "repositories": {
    "magesycho-magento2-easy-template-path-hints": {
      "type": "git",
      "url": ""

2. Registering the module package itself

composer require magepsycho/magento2-easy-template-path-hints:dev-master

Composer require command syntax:

composer require <vendor>/<package>:dev-<branch>

This will add new dependent package under node “require” as:

  "name": "magento/magento2ce",
  "description": "Magento 2 (Community Edition)",
  "type": "project",
  "require": {
    "magepsycho/magento2-easy-template-path-hints": "dev-master"

followed by Module installation from the repo.

Install Magento 2 Module from Github

Install Magento 2 Module from Github

Few Notes:
This approach will only work for the modules which has been packaged with composer.json
Please read more on Packaging a Magento 2 Module

If you are loading a package from VCS repository (git, svn etc.), version should be a branch name prefixed with ‘dev-‘ else you may get error like

The requested package magepsycho/magento2-easy-template-path-hints could not be found in any version, there may be a typo in the package name.


Enable Module

After the module has been downloaded from git repository, Module needs to be enabled.
1. Disable the cache under System->Cache Management
2. Run following Commands

php bin/magento module:enable MagePsycho_Easypathhints --clear-static-content
php bin/magento setup:upgrade

Go to Admin menu > Stores > Configuration, you will be able to see the ‘Easy Template Path Hints’ settings:

Easy Template Path Hints - Backend Settings

Easy Template Path Hints – Backend Settings

Disable Module

In order to disable the Module, simply run:

php bin/magento module:disable --clear-static-content MagePsycho_Easypathhints

That’s all.
Isn’t that more easier/powerful way of installing, enabling or disabling the Magento 2 Modules than Magento 1?

Magento 2 installation on MEMP (Mac OS X + Nginx + MySQL + PHP-FPM) stack

September 7, 2015  |  6 Comments  |  by Raj (MagePsycho)  |  Mac OS-X, Magento, Magento 2

Magento is a highly customizable e-commerce platform and content management system that you can use to build online storefronts or web sites for selling merchandise. Magento provides common e-commerce features, such as shopping carts and inventory management, and encourages extensive customization to meet your organization’s specific goals.

Magento 2 Merchant Beta codebase was released on July 15, 2015. This is a significant milestone before the general availability of Magento 2 in Q4 2015.

Before you begin installation

1. MEMP(Mac OS X + Nginx + MySQL + PHP-FPM) stack should already be installed & configured in your system. And system should meet the requirements discussed in Magento system requirements.

If MEMP stack is not installed, I would recommend homebrew package manager for installation.
2. Some Assumptions
Magento Dir: ~/Sites/opensource/magento/magento2beta
Virtual Host:

Once your MEMP system is ready meeting all the requirements, you are ready to move ahead for the installation.

Installation Steps

1. Create the project folder & clone the magento2 codebase

mkdir ~/Sites/opensource/magento/magento2beta && cd ~/Sites/opensource/magento/magento2beta
git clone .
Git Clone Magento2

Git Clone Magento2

2. Checkout to master branch

git checkout master

OR you can directly use the following command while cloning:

git clone -b master
Git Checkout Master Branch

Git Checkout Master Branch

You can clone either the master or develop branch:
– master is more stable
– develop is more recent

Initially we had an issue installating the sample data with develop branch, which resulted in the following error:

Fatal error: Call to undefined method Magento\Catalog\Model\Resource\Product\Interceptor::getWriteConnection() in app/code/Magento/SampleData/Module/Catalog/Setup/Product/Gallery.php on line 144

Sample data installation error in Magento 2

Sample data installation error

Due to recent changes, you can now use sample data with either the develop branch (more current) or the master branch.

3. File permission

chmod -R 755 ./

4. Update Magento dependencies using Composer
Install Composer if it’s not already installed:

curl -sS | php
mv composer.phar /usr/local/bin/composer

Now run Composer to update dependencies:

composer install

This command updates package dependencies and can take a few minutes to complete.

Update Magento dependencies using Composer

Update Magento dependencies using Composer

5. Install sample data before Magento installation

– Edit composer.son:
In the first section, add “minimum-stability”: “beta”, before license.

then run the following commands:

composer config repositories.magento composer
composer require magento/sample-data:1.0.0-beta

Sample Data Installation

Sample Data Installation Result

Note: You can also install sample data after Magento installaiton

Magento 2 dev team has an updated version on how to install sample data:

6: Finally install Magento System
Run following command in order to install the Magento system:

php bin/magento setup:install --base-url= \
--db-host=localhost \
--db-name=magento2beta \
--db-user=root \
--db-password=root \
--admin-firstname=Raj \
--admin-lastname=KB \ \
--admin-user=admin \
--admin-password=pass123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--sales-order-increment-prefix="ORD$" \
--session-save=db \
--use-rewrites=1 \
--use-sample-data \

To find more information on command options, please check the following url:

Magento 2 - CLI Installation

Magento 2 – CLI Installation

Magento 2 - Installation Complete!

Magento 2 – Installation Complete!

7: Installation Complete!
Now you can explore the frontend and backend.
Some Screenshots:

Magento 2 - Homepage

Magento 2 – Homepage

Magento 2 - Category Page

Magento 2 – Category Page

Magento 2 - Product Page

Magento 2 – Product Page

Magento 2 - Cart Page

Magento 2 – Cart Page

Magento 2 - Checkout Page

Magento 2 – Checkout Page

Magento 2 - Admin Dashboard

Magento 2 – Admin Dashboard

Have fun with Magento 2!