Magento fix for “No Administrators role was found, data fixture needs to be run”

SQL queries

INSERT INTO authorization_role (role_id, parent_id, tree_level, sort_order, role_type, user_id, user_type, role_name) VALUES (1, 0, 1, 1, 'G', 0, '2', 'Administrators');
INSERT INTO authorization_rule (rule_id, role_id, resource_id, privileges, permission) VALUES (1, 1, 'Magento_Backend::all', null, 'allow');

Magento 2 debug controller match

Useful if your custom controller is not firing

Places to check:
vendor/magento/framework/App/FrontController.php

 while (!$request->isDispatched() && $routingCycleCounter++ < 100) {
            /** @var \Magento\Framework\App\RouterInterface $router */
            foreach ($this->_routerList as $router) {
                try {
                    $actionInstance = $router->match($request);
                    if ($actionInstance) {
                        $result = $this->processRequest(

vendor/magento/framework/App/Router/Base.php

  foreach ($modules as $moduleName) {
            $currentModuleName = $moduleName;

            $actionClassName = $this->actionList->get($moduleName, $this->pathPrefix, $actionPath, $action);
            if (!$actionClassName || !is_subclass_of($actionClassName, $this->actionInterface)) {
                continue;
            }

            $actionInstance = $this->actionFactory->create($actionClassName);
            break;
        }

Magento 2 log all Mysql queries to log file

Edit file vendor/magento/framework/DB/Statement/Pdo/Mysql.php

            return $this->tryExecute(function () use ($params) {
                $writer = new \Zend_Log_Writer_Stream(BP . '/var/log/debugSql.log');
                $logger = new \Zend_Log();
                $logger->addWriter($writer);
                $logger->debug($this->_stmt->queryString);
                $logger->debug(json_encode($params));
                $logger->debug('================');
                return $params !== null ? $this->_stmt->execute($params) : $this->_stmt->execute();
            });

How to debug Magento 2 email templates

By help of a script you can send Shipment, Creditmemo etc emails how much you want

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

use Magento\Framework\App\Bootstrap;

require 'app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get(Magento\Framework\App\State::class);
$state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

/** @var Magento\Store\Model\App\Emulation $emulation */
$emulation = $objectManager->create('Magento\Store\Model\App\Emulation');
$emulation->startEnvironmentEmulation(1, \Magento\Framework\App\Area::AREA_FRONTEND, true);


/** @var \Magento\Sales\Model\ResourceModel\Order\Creditmemo\Collection $shipmentCollection */
$collection = $objectManager->get(\Magento\Sales\Model\ResourceModel\Order\Creditmemo\Collection::class);
/** @var Magento\Sales\Model\Order\Creditmemo $subject */
$subject = $collection->getLastItem();


/** @var Magento\Sales\Model\Order\Email\Sender\CreditmemoSender $sender */
$sender = $objectManager->get(Magento\Sales\Model\Order\Email\Sender\CreditmemoSender::class);
$sender->send($subject);


$emulation->stopEnvironmentEmulation();
echo "Done";

How to debug Magento 2 code with one file?

You can debug a lot of Magento 2 functions/logic with the help of only one script!
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

use Magento\Framework\App\Bootstrap;

require 'app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get(Magento\Framework\App\State::class);
$state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

/** @var Magento\Store\Model\App\Emulation $emulation */
$emulation = $objectManager->create('Magento\Store\Model\App\Emulation');
$emulation->startEnvironmentEmulation(1, \Magento\Framework\App\Area::AREA_FRONTEND, true);

foreach (range(1, 1) as $shipId) {

    /** @var Magento\Sales\Model\ResourceModel\Order\Shipment\Collection $shipmentCollection */
    $shipmentCollection = $objectManager->get(\Magento\Sales\Model\ResourceModel\Order\Shipment\Collection::class);
    /** @var Magento\Sales\Model\Order\Shipment $shipment */
    $shipment = $shipmentCollection->getItemById($shipId);

//$shipment->setSendEmail(1);

    /** @var Magento\Sales\Model\Order\Email\Sender\ShipmentSender $sender */
    $sender = $objectManager->get(Magento\Sales\Model\Order\Email\Sender\ShipmentSender::class);
    $sender->send($shipment);

    /** @var \Magento\Sales\Model\ResourceModel\Order\Collection $orderCollection */
    $orderCollection = $objectManager->get(\Magento\Sales\Model\ResourceModel\Order\Collection::class);
    /** @var Magento\Sales\Model\Order\Email\Sender\OrderSender $sender */
    $sender = $objectManager->get(Magento\Sales\Model\Order\Email\Sender\OrderSender::class);
//$order=$orderCollection->getItemById(26);
//$sender->send($shipment->getOrder());
//print_r($order->debug());
//echo "\n".$order->getCustomerEmail();

}

$emulation->stopEnvironmentEmulation();
echo "Done";