How to reindex indexer programmatically in magento 2?

Just create PHP file under your module’s Cron folder,
A created module like Rbj_Indexing for reference, Create Indexer.php file and call execute() function,

There are two types of method for indexing.

1. Regenerate indexes for all indexers

2. Regenerate indexes for all invalid indexers. This will only regenerate for invalid indexer.

How to override template (.phtml) files in magento 2?

Override template files in Magento 2 is common and just a simple. You can override template file by below ways.
1. Using Theme level in the theme directory
2. Using Module level in the custom module

1. Using Theme level,
We will discuss first theme level override templates. I hope you have created theme for your site. If you don’t know how to create theme refer to link for creating the custom theme,
For theme level override you must have a custom theme in your project.
Let’s assume We need to override list.phtml file from Catalog core module.
Path for core module is vendor/magento/module-catalog/view/frontend/templates/product/list.phtml

We need to create Magento_Catalog folder in our theme root directory.
Let’s assume your theme name is Vendorname/themename. Your actual path for a theme is,
app/design/frontendVendorname/themename. You need to create Folder Magento_Catalog for override catalog module template file. Our core module template resides in module-catalog folder so you need to create Core module folder like,
Magento_Catalog (Where Magento is Vendorname and Modulename will be in UpperCamelCase letter with suffix “prefix”)

Now you can override your list.phtml at below location,,
Create list.phtml file and get content from core Magento Catalog template list.phtml file.

For some core module name in Magento 2 has multiple words separated with the hyphen(-).
Like, module-configurable-product, In this case, our Module name in the theme will be, Magento_ConfigurableProduct
if you want to override templates from module-checkout-agreements your theme level folder will be Magento_CheckoutAgreements

2. Using Module Level,
You can override template file using the Module level.
You need to create layout XML file from your controller action,

(Using New method)

(Using old deprecated method, action method=”setTemplate”)

Using New method some of the templates is still not overridden check link, Github Issue.

For example, in your module, you would put a list template in  module for path, app/code/<Vendor>_<Module>/view/frontend/templates/product/list.phtml


Which method should we use from the above solutions?
There is no one specific method that should be used in all scenarios.
If you are creating a theme, use the template path method(Method 1 is more suitable for frontend developer).
If you are creating a module, use the layout at the module level and define your template.



How to override Customer form/login.phtml file to custom module in magento 2?

We can override form/login.phtml file by just copy login.phtml file to our theme level easily without any code customization. login.phtml file contains the code of login form of site,They contain email and password field.

For custom module requirement, we need to overwrite login.phtml file in module level so we need to create customer_account_login.xml file.
Create XML file at app/code/Rbj/Customer/view/frontend/layout/customer_account_login.xml

Now keep our login.phtml file at app/code/Rbj/Customer/view/frontend/templates/form/login.phtml
Keep content from core login.phtml file to our custom file.
Run command,
php bin/magento cache:clean

Open link, {YOUR_SITE_URL}/customer/account/login
You can get your override file changes.