How to setup cron jobs in Magento 2 with Cpanel and SSH

In this tutorial, we will guide you how to setup cron jobs in Magento 2 with Cpanel and Command line ( using SSH access)

Setup Cron jobs in Magento 2 with Cpanel

Step1 : Login your Cpanel and go to Advanced -> Cron Jobs, you will see the list of cron jobs on your server.

Step 2: You need to add following commands one by one and make them run once per minute.

YOUR_MAGENTO2_PATH is the absolute path of your magento 2 installation directory.

Setup cron jobs in Magento 2 with Cpanel

Step 3: This is an example when you added all commands exactly.

Setup cron jobs in Magento 2 with Cpanel


Setup Cron job in Magento 2 with command line ( using SSH access )

Step 1: Login ssh with your Magento 2 directory owner then execute command:

or if you logged in as root access you can use this command

magento_directory_owner is the owner of Magento 2 directory.

Step 2: You will be able to add cron jobs for this user, add following lines:

If you want to edit crontab with nano, you can execute this command instead:

Step 3: After saving crontab, you need to restart cron service on your server, use this command:

That’s how to setup cron jobs in Magento 2 with Cpanel or SSH access. Hope that it will be helpful.

If you have any question, please leave a comment. 

Magento 2 Manage Indexer using command line

Indexing is how Magento transforms data ( products, categories … ), to improve the performance of your storefront.
Magento stores lots of data (including catalog data, prices, users, stores … ) in many database tables. To optimize storefront performance, Magento accumulates data into special tables using indexers.

For example, you change the price of an item from $4.99 to $3.99. Magento must reindex the price change to display it on your storefront.

Let’s see how to manage, refresh indexers in Magento 2 using command line via SSH

1. Magento 2 indexers

In default, there are 10 indexers:

  • Design Config Grid ( name: design_config_grid )
  • Customer Grid ( name : customer_grid )
  • Category products ( name: catalog_category_product )
  • Product categories ( name: catalog_product_category)
  • Product price ( name: catalog_product_price)
  • Product entity attribute value ( name: catalog_product_attribute)
  • Catalog search ( name: catalogsearch_fulltext)
  • Stock ( name: cataloginventory_stock)
  • Catalog rule product ( name: catalogrule_rule)
  • Catalog product rule ( name: catalogrule_product)

We can get indexer info using command:

2. Indexer status

An indexer status can be one of following:

  • valid: data is synchronized, no reindex required
  • invalid: the original data was changed, the index should be updated
  • working: indexing is in progress

We can get indexer status using command:

3. Indexing modes

Re-indexing can be performed in two modes:

  • Update on Save: index tables are updated immediately after the dictionary data ( product, category, store…) is changed.
  • Update by Schedule: index tables are updated by cron job according to the configured schedule.

We can check indexer’s mode using command:

To change indexer mode, we use command

“realtime” is equal to  “Update on Save” and “schedule” is equal to “Update by Schedule”.

4. Re-index

Besides using “System -> Index Management” in Magento backend, we also can re-index using command:

We will get the result like:

5. Reset indexer when it’s locked.

During re-index process, you may get the message like:

So we need to reset that indexer status to be able to re-index ( in this case, it’s “cataloginventory_stock” )

We can reset indexer using command:

That’s how we can manage Magento 2 indexers. Please leave a comment or contact us if you have any question.

Thank you!

Manage cache Magento 2 using command line

Manage cache Magento 2 using command line – In Magento 2 there are 2 ways to manage cache, going to “System -> Cache Management” in backend or using command line.

You can run commands in following ways:

  • cd <your Magento install dir>/bin and run them as ./magento <command name>
  • php <your Magento install dir>/bin/magento <command name>

1. View the cache status

magento cache:status

You can get a result like this:

1 means “Enabled”  and 0 means “Disabled”

2. Enable or Disable cache types

This command enables or disables all cache types or only the ones you specify

You can get each cache type code and its description here.


Above commands will enable/disable all cache types. You will get the cache types status after running the command.

3. Clean and Flush cache types.

What’s different between “Clean” and “Flush”

  • Cleaning a cache type deletes all items from enabled Magento cache types only. In other words, this option does not affect other processes or applications because it cleans only the cache that Magento uses.Disabled cache types are not cleaned.
  • Flushing a cache type purges the cache storage, which might affect other processes applications that are using the same storage.Flush cache types if you’ve already tried cleaning the cache and you’re still having issues that you cannot isolate.


Please note:

magento cache:flush is equivalent “Flush Storage Cache” in System -> Cache Management

magento cache:clean is equivalent “Flush Magento Cache” in System-> Cache Management

That’s how we can manage cache Magento 2 using command line. 

Magento 2 get Base URL

Magento 2 get Base URL – As you know, in Magento 1 we can easily get base url using function:

In this tutorial, let’s find out how to get base url in Magento 2

In Magento 2, we can get base url using an instance of StoreManagerInterface 

1. Create an instance of StoreManagerInterface in __construct function.

Then we can get base url using function

We also can get url for media, static, js directory:

2. In another way, we can create an instance of StoreManagerInterface using ObjectManager:

That’s how to get base url in Magento 2. See you in the next tutorial.

Magento 2 Add a menu item in backend

In this blog post we will see how to add a menu item in backend for your Magento 2 module.

1. Create file VendorName/ModuleName/etc/menu.xml

The admin menu in Magento 2 has 3 parts:

  • The main admin menu title which shows up in left sidebar
  • Submenu title
  • Actual menu

2. Create file VendorName/ModuleName/etc/acl.xml

3. Create Admin Routes with file: VendorName/ModuleName/etc/adminhtml/routes.xml

with content:

4. Create a backend controller to handle menu item url


Finally, when you click on the new menu item, you will see “Hello World” in a page.

If something is wroing, you will be redirected to dashboard automatically.

That’s how to add a menu item in backend Magento 2, see you in other posts.

Magento 2 – Create system configuration – system.xml

In this blog post we will see how to create System Configuration for your module in Magento 2

System configuration in Magento 2 is very similar to Magento 1

System configuration is divided into different parts; tab, section, group and field which is described in magento1 blog. This same concepts are used in Magento2 as well.

1. Create VendorName/ModuleName/etc/adminhtml/system.xml file

with content

2. Set default values for these configuration item

Create file: VendorName/ModuleName/etc/config.xml

3. Create ACL file

Create file: VendorName/ModuleName/etc/acl.xml

Now when you open Magento admin, you see the “Test” tab and sections.
You might get an error 404 Not Found first time, just logout and login again to fix this.

That’s how to create store configuration in Magento 2. See you in other tutorials.


Magento 2 Fix Issue “No Region Found within the Locale…”

In Magento 2 sometimes, an error displays: No region found within the locale “de” (or other locale code). In this topic we will give you a solution for this issue.

How to get bug “No Region Found within the Locale…”

You have to setup language for your browser. Example with google chrome: Setting → Language → Choose your language → Done No Region Found within the Locale Magento 2 No Region Found within the Locale Magento 2

Then please refresh your browser you can get the bug if your extension use \Magento\Framework\CurrencyInterface

How to fix it?

We should use try catch function when define CurrencyInterface

Refresh your browser and this issue has gone.

That is the shortest process for you to  Fix Issue “No Region Found within the Locale…” in Magento 2 . With this guide, you can manage the Issue “No Region Found within the Locale…” in Magento 2 easily.

Thank you for reading this post and see you in other posts

Magento 2 Compile error: “No tokens were provided”

Magento 2 Compile error: “No tokens were provided”

In Magento 2, when you run “setup:di:compile” you may get error message:

“No tokens were provided”

That error message is caused by an empty file. You can find it using command:

It usually comes from an additional extension, just delete the empty file and run compilation again using:

I hope this will help. If you have any question, leave a comment or contact us.


Magento 2 Render WYSIWYG content

Render WYSIWYG Magento 2 – In this tutorial, we’re going to tell you how to render WYSIWYG Magento 2.

Some cases, you save your data using WYSIWYG editor then you want to render it in frontend.

With Magento 1, you can do it in this way:

However, in Magento 2, there is no BlockTemplateProcessor. We need to use this method instead:

Hope this could help.

Magento 2 Send Email Programmatically

Magento 2 send email programmatically – In this post, let’s find out how to send email programmatically in Magento 2. It will be useful for you in your custom module or new feature. What we need to do:

  • Create your email template in a html file.
  • Declare your email template.
  • Create a function to send your email.

We’re doing step by step:

Create new html file


with simple content:

Declare your email template, create xml file


with content:

Finally, create a function to send your email.

In this tutorial, we’re using a controller action. Create file:


with content:

You also can create this function in helper, model …

If you have any question, just leave a comment or contact us.