Monday 29 June 2020

How to protect file from public access in Drupal 8?

If we don't want to show any file or folder to 'Anonymous user', 'Authenticated user' then we have 2 options.

1. We can set the 'Permission' for this file or folder.
2. If we are using Pantheon server then we have 'pantheon.yml' file on root.
Write the code there.

protected_web_paths:
  - /web.config
  - /core/package.json

And this way easily we can protect our file or folder from unknown users.



Note: If have any suggestions or issue regarding 'How to protect file from public access in Drupal 8?' then you can ask by comments. 

Sunday 28 June 2020

How to set the flood limit in Drupal 8?

Sometimes, we get the flood of Unlimited attempts of login fail message, block user, block IP. In that case our website handle unwanted extra data, extra burden on database that is not good for our website health.
So what we have to do, in Drupal 7, we have module that name is "Flood control" https://www.drupal.org/project/flood_control

But in Drupal 8 we don't have that module, So many times we get the error message that is very famous: "Login blocked after 5 failed login attempts".
In that case or if we want to overcome this problem Drupal 8 we have solution, we are going to share:

Code for Flood limit change:

$flood_limit = 5;                 //Default value is 5, change whatever you want. 
// for login form
\Drupal::configFactory()->getEditable('login.settings')
      ->set('flood.limit', $flood_limit)
      ->save();
// for contact form
$flood_limit = 5;                //Default value is 5, change whatever you want. 
\Drupal::configFactory()->getEditable('contact.settings')
      ->set('flood.limit', $flood_limit)
      ->save();   
  
Code for Flood interval change:

// for login form
$flood_interval = 3600;      //Default value is 3600sec (1hour), change whatever you want
 \Drupal::configFactory()->getEditable('login.settings')
      ->set('flood.interval', $flood_interval)
      ->save();
// for contact form
$flood_interval = 3600;     //Default value is 3600sec (1hour), change whatever you want
 \Drupal::configFactory()->getEditable('contact.settings')
      ->set('flood.interval', $flood_interval)
      ->save();   

  
Important Notice: Put this code in custom module or template or theme file.

Or we can use 'settings.php' option for this code
$flood_limit = 10;
$config['login.settings']['flood']['limit'] = $flood_limit; 

And another we have a module in drupal 8, we can use this and all this code feature is there. Please find this "Flood settings" module. https://www.drupal.org/project/flood_settings 
Note: If have any suggestions or issue regarding 'How to set the flood limit in Drupal 8?' then you can ask by comments.  

Saturday 27 June 2020

How to check log error messages in Drupal 8?

As we know about log messages in Drupal, Log messages are our project related, every user related track (error, notice, warning, failure, PHP issue). In our Drupal we can check that track with URL '/admin/reports/dblog'.



And if we create a custom Module and we want to track every event of module, every time activity that we can write that code in this module.

Logs with an arbitrary level:
\Drupal::logger('module_name')->log($message); //When a module was installed

Normal but significant events:
\Drupal::logger('module_name')->notice($message); //Normals events, as cron execution

Exceptional occurrences:
\Drupal::logger('module_name')->warning($message); //exceptional cases not an error

Errors:
\Drupal::logger('module_name')->error($message); //error messages

And If we have requirement that we want to track this log error message by File
In that case we have a Drupal 8 module that we can install "File Log" module.

After configure, that file will be Create in root area Bydefault "site/default/files/logs".
I am going to share that module link here.

Note: If have any suggestions or issue regarding 'How to check log error messages in Drupal 8?' then you can ask by comments.  

How to resolve max execution time error in drupal ?

When you found error regarding 'max_execution_time' exceed, then you can follow steps for resolve this error: Steps:   You can put t...