Create custom Drush command

Create in module directory file named drush.services.yml with similar content:

services:
  custom_base.commands:
    class: Drupal\custom_base\Commands\CustomCommands
    arguments:
      - '@config.factory'
      - '@entity_type.manager'
      - '@database'
    tags:
      -  { name: drush.command }

In Drupal\custom_base\src\Commands need to create file CustomCommands.php:

Git commands

To remove files from the GIT repository based on .gitignore, without deleting them from the local file system:

git ls-files -i -c -X .gitignore | xargs git rm --cached

Restore admin user

Programaticaly restore admin user could be done with this code:

use Drupal\user\Entity\User;
$user = User::create([ 
'name' => 'admin', 
'mail' => 'admin@example.com', 
'status' => 1,
'roles' => ['administrator'],
'pass' => 'newpassword',
]); 
$user->save();

Translate

<h1>{{ 'Hello world'|t }}</h1>
<div class="mt-3 alert alert-warning">
    <p>{% trans %}Do you know how translation works?{% endtrans %}</p>
</div>

Using translate function with parameters:

{{ 'Last checked: @time ago'|t({'@time': time}) }}

 

 

{{ "Text to translate"|t({}, {'context' : 'Context name'}) }}

and

Commerce

Load Order and change it status to "Cancelled":

$order = \Drupal::entityTypeManager()
->getStorage('commerce_order')
 ->load(1);
$order->getState()->applyTransitionById('cancel');
$order->save();

Nginx fixes in config

To detect if there are any errors:

nginx -T

To fix 504 Timeout error: 

upstream timed out: fastcgi_read_timeout 600s;

To fix error "upstream sent too big header while reading response header from upstream" need to append the following directives:

fastcgi_buffers 16 32k;
fastcgi_buffer_size 64k;
fastcgi_busy_buffers_size 64k;
#fastcgi_buffering off;
large_client_header_buffers 4 8k;

Changes for Settings.php file

Drupal 7:

$conf['file_temporary_path'] = 'files/tmp';
$conf['file_private_path'] = 'files/private';
$conf['file_public_path'] = 'files/public';

Drupal 8+:

$settings['config_sync_directory'] = '../config/sync';
$settings['file_public_path'] = '../files/public';
$settings['file_private_path'] = '../files/private';
$settings['file_temp_path'] = '../files/tmp';
$settings['trusted_host_patterns'] = [
  '^example\.com$',
];