Setup Magento2 Cron job by command line

Steps to Create the crontab :

First, Open the Terminal and log in with the root user. After that go to Magento Root Path then run the below command:

Output:

cron install by command line

Crontab is created and saved.

Crontab is created and saved

NOTE: Use –force to rewrite an existing Magento crontab.

  • magento cron:install does not rewrite an existing crontab inside #~ MAGENTO START and #~ MAGENTO END comments in crontab.
  • magento cron:install –force does not affect any cron jobs outside Magento comments.

To check crontab List, run the below command:

Output:

check cron tab list

Steps to Run cron from the command line

Log in with the root user in the terminal. Go to Magento Root Path After running the below command:

Output:

cron run magento 2

Ran jobs by schedule.

where –group defines the cron group to run (eliminate this alternative if you want to run cron for all groups)

To run the indexing cron job, enter:

To run the default cron job, enter:

Steps to Remove the Magento crontab:

First Open Terminal and login with the root user and go to Magento Root Path After running the below command :

Output:

remove cron tab magento 2

Magento cron tasks have been removed

Magento2 Reindexing via SSH/CLI

ometimes you need to issue reindex instantly. For that SSH/CLI method is more suitable. Here is what you need to do:

  1. Log in to your store via SSH/CLI and navigate to the root of your store.
  2. Run the following command: bin/magento indexer:reindex

You should see the following log, which shows, that reindex was successfully completed:

Design Config Grid index has been rebuilt successfully in 00:00:00
Customer Grid index has been rebuilt successfully in 00:00:00
Category Products index has been rebuilt successfully in 00:00:00
Product Categories index has been rebuilt successfully in 00:00:00
Product Price index has been rebuilt successfully in 00:00:01
Product EAV index has been rebuilt successfully in 00:00:01
Catalog Search index has been rebuilt successfully in 00:00:01
Stock index has been rebuilt successfully in 00:00:00
Catalog Rule Product index has been rebuilt successfully in 00:00:01
Catalog Product Rule index has been rebuilt successfully in 00:00:00
Unable to go back to Default Mode getting error Magento2

I was in production mode and was getting an error when trying to go back to default mode

run below commands in sequence.

  • php bin/magento setup:di:compile
  • php bin/magento setup:upgrade
  • php bin/magento cache:clean
  • php bin/magento cache:flush

and then try to det default mode again, it should work now

bin/magento deploy:mode:set default

 

rm -rf var/view_preprocessed/* var/cache/* pub/static/*

Update No Reach Results Page, Magento2

There are 2 templates being used for result, one for simple search ( using top search field ) and other is for advance search field :

For Top search field result :

module_catalog-search/view/frontend/templates/result.phtml

For Advance Search result :

module_catalog-search/view/frontend/templates/advanced/result.phtml

And both search fields search data / record within product catalog, override the template(s), and add your condition in that template to show whatever data you want to show if there is no record is returned.

Easiest way to add Magento2 Goole Tag Manager Without Extensions

You can easily add GTM without third-party extensions. All you need is to add the GTM code to your active theme. The GTM code consist of two parts: script and noscript.
You need to put the GTM snippet into these two phtml templates for head and body:

New File#1

// YourTheme/Magento_Theme/templates/html/gtm_head.phtml
<script>..</script> <!– GTM code –>  add the GTM head code

New File#1

// YourTheme/Magento_Theme/templates/html/gtm_body.phtml
<noscript>..</noscript> <!– GTM code –> add the GTM no script code

To load the files correspondingly you should use the default .xml file:

<!– YourTheme/Magento_Theme/layout/default.xml –>
<referenceContainer name=”head.additional”>
<block class=”Magento\Framework\View\Element\Template” name=”gtm.head” before=”-” template=”Magento_Theme::html/gtm_head.phtml” />
</referenceContainer>

<referenceContainer name=”after.body.start”>
<block class=”Magento\Framework\View\Element\Template” name=”gtm.body” before=”-” template=”Magento_Theme::html/gtm_body.phtml” />
</referenceContainer>

How to Properly set Production Mode and compilation in Magento2

In Magento 2, You do not need to run static:content:deploy command every time when your Magento mode is default or developer, but when you change Magento mode to production at that time Magento will not generate static content file automatically.

So you need to run deploy commands in this sequence..

You can change your Magento mode from developer to production using below command.

php bin/magento deploy:mode:set production --skip-compilation

After running above command your Magento mode will be change from developer to production, then you need to run below commands.

php bin/magento setup:upgrade
php bin/magento setup:di:compile
or php -dmemory_limit=-1 bin/magento setup:di:compile
 php bin/magento cache:clean 
php bin/magento cache:flush 
php bin/magento setup:static-content:deploy -f en_US bg_BG
php -dmemory_limit=-1 bin/magento setup:static-content:deploy -f en_US  
//www.expertwebsolutionsinc.com/wp-content/uploads/2020/06/expertwebsoutions-bottom.png