<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Syed Shazeedul Islam]]></title><description><![CDATA[Software Engineer]]></description><link>https://blog.shazeedul.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1720593953812/840ce888-803b-4461-8129-a2da27b70b78.png</url><title>Syed Shazeedul Islam</title><link>https://blog.shazeedul.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 01:31:09 GMT</lastBuildDate><atom:link href="https://blog.shazeedul.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Modular Monolith with Clean Architecture.]]></title><description><![CDATA[Modular Monolith with Clean Architecture in Laravel
A practical implementation-level example for building a modular monolith using clean architecture in Laravel/PHP.
This document is written to be sha]]></description><link>https://blog.shazeedul.dev/modular-monolith-with-clean-architecture</link><guid isPermaLink="true">https://blog.shazeedul.dev/modular-monolith-with-clean-architecture</guid><category><![CDATA[Architecture Design]]></category><category><![CDATA[Clean Architecture]]></category><dc:creator><![CDATA[Syed Shazeedul Islam]]></dc:creator><pubDate>Sun, 29 Mar 2026 07:58:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/668d00ea32e1643b75a2d676/4ad71f39-ea8b-4740-9195-d72f27e60ce2.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>Modular Monolith with Clean Architecture in Laravel</h1>
<p>A practical implementation-level example for building a <strong>modular monolith</strong> using <strong>clean architecture</strong> in <strong>Laravel/PHP</strong>.</p>
<p>This document is written to be shared with engineers who want a concrete reference for structuring modules, separating business logic from frameworks, and keeping inter-module boundaries clean.</p>
<h2>1. Goal</h2>
<p>This architecture aims to achieve:</p>
<ul>
<li><strong>one deployable application</strong></li>
<li><strong>multiple business modules</strong></li>
<li><strong>clear code ownership per module</strong></li>
<li><strong>framework-independent domain logic</strong></li>
<li><strong>controlled communication between modules</strong></li>
</ul>
<p>This is a <strong>modular monolith</strong>, not microservices.</p>
<p>That means:</p>
<ul>
<li>one Laravel application</li>
<li>one deployment unit</li>
<li>usually one database</li>
<li>modules separated by code boundaries, not network boundaries</li>
</ul>
<h2>2. Core Architecture Rules</h2>
<h3>Rule 1: Keep business logic away from Laravel details</h3>
<p>Business rules should not depend directly on:</p>
<ul>
<li>controllers</li>
<li>requests</li>
<li>Eloquent models</li>
<li>facades</li>
<li>route files</li>
</ul>
<h3>Rule 2: Modules talk through contracts</h3>
<p>A module should not directly use another module's internal database models or repositories.</p>
<p>Use:</p>
<ul>
<li>interfaces</li>
<li>gateways</li>
<li>application contracts</li>
<li>domain events when needed</li>
</ul>
<h3>Rule 3: Dependency direction goes inward</h3>
<pre><code class="language-text">Presentation -&gt; Application -&gt; Domain
Infrastructure -&gt; Application / Domain
</code></pre>
<p>The domain should be the most stable and framework-independent part.</p>
<h2>3. Example Business Flow</h2>
<p>We will model this use case:</p>
<p><strong>Place Order</strong>
Flow:</p>
<ol>
<li>User sends an order request</li>
<li>Orders module validates input</li>
<li>Orders use case builds the order</li>
<li>Orders asks Inventory to reserve stock</li>
<li>Inventory checks and decrements stock</li>
<li>Orders saves the order</li>
<li>API returns the created order</li>
</ol>
<h2>4. Suggested Folder Structure</h2>
<pre><code class="language-text">app/
  Modules/
    Orders/
      Domain/
        Entities/
          Order.php
          OrderItem.php
        Repositories/
          OrderRepositoryInterface.php
        Services/
          InventoryGatewayInterface.php
        Exceptions/
          InsufficientStockException.php

      Application/
        DTOs/
          PlaceOrderCommand.php
        UseCases/
          PlaceOrder.php

      Infrastructure/
        Persistence/
          Eloquent/
            Models/
              OrderModel.php
              OrderItemModel.php
            Repositories/
              EloquentOrderRepository.php
        Providers/
          OrdersServiceProvider.php

      Presentation/
        Http/
          Controllers/
            OrderController.php
          Requests/
            PlaceOrderRequest.php
          Resources/
            OrderResource.php
        Routes/
          api.php

      Database/
        Migrations/
          2026_03_29_000001_create_orders_table.php
          2026_03_29_000002_create_order_items_table.php
        Factories/
        Seeders/

    Inventory/
      Domain/
        Repositories/
          ProductStockRepositoryInterface.php

      Application/
        Services/
          ReserveStockService.php

      Infrastructure/
        Persistence/
          Eloquent/
            Models/
              ProductStockModel.php
            Repositories/
              EloquentProductStockRepository.php
        Services/
          StockReservationService.php
        Providers/
          InventoryServiceProvider.php

      Database/
        Migrations/
          2026_03_29_000003_create_product_stocks_table.php

    Shared/
      Domain/
        ValueObjects/
          Money.php
      Application/
        Contracts/
          ClockInterface.php
</code></pre>
<h2>5. What Each Layer Does</h2>
<h3>Domain</h3>
<p>Contains pure business concepts and rules.</p>
<p>Examples:</p>
<ul>
<li>entities</li>
<li>value objects</li>
<li>repository interfaces</li>
<li>business exceptions</li>
<li>gateway contracts</li>
</ul>
<p>Domain should not know Laravel exists.</p>
<h3>Application</h3>
<p>Contains use cases.</p>
<p>Examples:</p>
<ul>
<li><code>PlaceOrder</code></li>
<li><code>CancelOrder</code></li>
<li><code>RefundPayment</code></li>
</ul>
<p>Application orchestrates business flow using domain contracts.</p>
<h3>Infrastructure</h3>
<p>Contains Laravel and persistence details.</p>
<p>Examples:</p>
<ul>
<li>Eloquent models</li>
<li>repository implementations</li>
<li>service provider bindings</li>
<li>adapter implementations</li>
</ul>
<h3>Presentation</h3>
<p>Contains delivery-layer code.</p>
<p>Examples:</p>
<ul>
<li>controllers</li>
<li>form requests</li>
<li>API resources</li>
<li>routes</li>
</ul>
<h2>6. Orders Module Implementation</h2>
<h3>6.1 Domain Entity: <code>Order</code></h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Domain\Entities;

class Order
{
    private ?int $id;
    private int $userId;
    private string $status;

    /** @var OrderItem[] */
    private array $items = [];

    public function __construct(?int \(id, int \)userId, array \(items, string \)status = 'pending')
    {
        \(this-&gt;id = \)id;
        \(this-&gt;userId = \)userId;
        \(this-&gt;items = \)items;
        \(this-&gt;status = \)status;
    }

    public static function create(int \(userId, array \)items): self
    {
        if (empty($items)) {
            throw new \InvalidArgumentException('Order must have at least one item.');
        }

        return new self(
            id: null,
            userId: $userId,
            items: $items,
            status: 'pending',
        );
    }

    public function confirm(): void
    {
        $this-&gt;status = 'confirmed';
    }

    public function getId(): ?int
    {
        return $this-&gt;id;
    }

    public function setId(int $id): void
    {
        \(this-&gt;id = \)id;
    }

    public function getUserId(): int
    {
        return $this-&gt;userId;
    }

    public function getStatus(): string
    {
        return $this-&gt;status;
    }

    /** @return OrderItem[] */
    public function getItems(): array
    {
        return $this-&gt;items;
    }
}
</code></pre>
<h3>6.2 Domain Entity: <code>OrderItem</code></h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Domain\Entities;

class OrderItem
{
    public function __construct(
        private int $productId,
        private int $quantity,
        private int $unitPrice,
    ) {
        if ($quantity &lt; 1) {
            throw new \InvalidArgumentException('Quantity must be at least 1.');
        }
    }

    public function getProductId(): int
    {
        return $this-&gt;productId;
    }

    public function getQuantity(): int
    {
        return $this-&gt;quantity;
    }

    public function getUnitPrice(): int
    {
        return $this-&gt;unitPrice;
    }

    public function getSubtotal(): int
    {
        return \(this-&gt;quantity * \)this-&gt;unitPrice;
    }
}
</code></pre>
<h3>6.3 Repository Contract</h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Domain\Repositories;

use App\Modules\Orders\Domain\Entities\Order;

interface OrderRepositoryInterface
{
    public function save(Order $order): Order;

    public function findById(int $id): ?Order;
}
</code></pre>
<h3>6.4 Cross-Module Contract: Inventory Gateway</h3>
<p>Orders should not directly use Inventory Eloquent models.</p>
<p>Instead, it depends on an abstraction.</p>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Domain\Services;

interface InventoryGatewayInterface
{
    /**
     * @param array&lt;int, array{product_id:int, quantity:int}&gt; $items
     */
    public function reserve(array $items): void;
}
</code></pre>
<h2>7. Orders Application Layer</h2>
<h3>7.1 Command DTO</h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Application\DTOs;

class PlaceOrderCommand
{
    /**
     * @param array&lt;int, array{product_id:int, quantity:int, unit_price:int}&gt; $items
     */
    public function __construct(
        public readonly int $userId,
        public readonly array $items,
    ) {}
}
</code></pre>
<h3>7.2 Use Case: <code>PlaceOrder</code></h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Application\UseCases;

use App\Modules\Orders\Application\DTOs\PlaceOrderCommand;
use App\Modules\Orders\Domain\Entities\Order;
use App\Modules\Orders\Domain\Entities\OrderItem;
use App\Modules\Orders\Domain\Repositories\OrderRepositoryInterface;
use App\Modules\Orders\Domain\Services\InventoryGatewayInterface;

class PlaceOrder
{
    public function __construct(
        private OrderRepositoryInterface $orders,
        private InventoryGatewayInterface $inventoryGateway,
    ) {}

    public function execute(PlaceOrderCommand $command): Order
    {
        $items = array_map(
            fn (array $item) =&gt; new OrderItem(
                productId: $item['product_id'],
                quantity: $item['quantity'],
                unitPrice: $item['unit_price'],
            ),
            $command-&gt;items
        );

        $order = Order::create(
            userId: $command-&gt;userId,
            items: $items,
        );

        $reservationItems = array_map(
            fn (OrderItem $item) =&gt; [
                'product_id' =&gt; $item-&gt;getProductId(),
                'quantity' =&gt; $item-&gt;getQuantity(),
            ],
            $items
        );

        \(this-&gt;inventoryGateway-&gt;reserve(\)reservationItems);

        $order-&gt;confirm();

        return \(this-&gt;orders-&gt;save(\)order);
    }
}
</code></pre>
<h3>Why this is clean</h3>
<p>This use case knows nothing about:</p>
<ul>
<li>HTTP request objects</li>
<li>controllers</li>
<li>Eloquent</li>
<li>facades</li>
<li>route definitions</li>
</ul>
<p>It only works with domain entities and contracts.</p>
<h2>8. Inventory Module Implementation</h2>
<h3>8.1 Inventory Repository Contract</h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Inventory\Domain\Repositories;

interface ProductStockRepositoryInterface
{
    public function getAvailableQuantity(int $productId): int;

    public function decrement(int \(productId, int \)quantity): void;
}
</code></pre>
<h3>8.2 Application Service: <code>ReserveStockService</code></h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Inventory\Application\Services;

use App\Modules\Inventory\Domain\Repositories\ProductStockRepositoryInterface;

class ReserveStockService
{
    public function __construct(
        private ProductStockRepositoryInterface $stocks,
    ) {}

    /**
     * @param array&lt;int, array{product_id:int, quantity:int}&gt; $items
     */
    public function execute(array $items): void
    {
        foreach (\(items as \)item) {
            \(available = \)this-&gt;stocks-&gt;getAvailableQuantity($item['product_id']);

            if (\(available &lt; \)item['quantity']) {
                throw new \RuntimeException(
                    "Insufficient stock for product {$item['product_id']}"
                );
            }
        }

        foreach (\(items as \)item) {
            \(this-&gt;stocks-&gt;decrement(\)item['product_id'], $item['quantity']);
        }
    }
}
</code></pre>
<h3>8.3 Adapter Exposed to Orders</h3>
<p>Inventory implements the contract that Orders depends on.</p>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Inventory\Infrastructure\Services;

use App\Modules\Inventory\Application\Services\ReserveStockService;
use App\Modules\Orders\Domain\Services\InventoryGatewayInterface;

class StockReservationService implements InventoryGatewayInterface
{
    public function __construct(
        private ReserveStockService $reserveStockService,
    ) {}

    public function reserve(array $items): void
    {
        \(this-&gt;reserveStockService-&gt;execute(\)items);
    }
}
</code></pre>
<p>This is the clean boundary between modules.</p>
<hr />
<h2>9. Infrastructure Layer</h2>
<h3>9.1 Eloquent Models</h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Infrastructure\Persistence\Eloquent\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class OrderModel extends Model
{
    protected $table = 'orders';

    protected $fillable = [
        'user_id',
        'status',
    ];

    public function items(): HasMany
    {
        return $this-&gt;hasMany(OrderItemModel::class, 'order_id');
    }
}
</code></pre>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Infrastructure\Persistence\Eloquent\Models;

use Illuminate\Database\Eloquent\Model;

class OrderItemModel extends Model
{
    protected $table = 'order_items';

    protected $fillable = [
        'order_id',
        'product_id',
        'quantity',
        'unit_price',
    ];
}
</code></pre>
<h3>9.2 Repository Implementation</h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Infrastructure\Persistence\Eloquent\Repositories;

use App\Modules\Orders\Domain\Entities\Order;
use App\Modules\Orders\Domain\Entities\OrderItem;
use App\Modules\Orders\Domain\Repositories\OrderRepositoryInterface;
use App\Modules\Orders\Infrastructure\Persistence\Eloquent\Models\OrderItemModel;
use App\Modules\Orders\Infrastructure\Persistence\Eloquent\Models\OrderModel;
use Illuminate\Support\Facades\DB;

class EloquentOrderRepository implements OrderRepositoryInterface
{
    public function save(Order $order): Order
    {
        return DB::transaction(function () use ($order) {
            $orderModel = OrderModel::create([
                'user_id' =&gt; $order-&gt;getUserId(),
                'status' =&gt; $order-&gt;getStatus(),
            ]);

            foreach (\(order-&gt;getItems() as \)item) {
                OrderItemModel::create([
                    'order_id' =&gt; $orderModel-&gt;id,
                    'product_id' =&gt; $item-&gt;getProductId(),
                    'quantity' =&gt; $item-&gt;getQuantity(),
                    'unit_price' =&gt; $item-&gt;getUnitPrice(),
                ]);
            }

            return new Order(
                id: $orderModel-&gt;id,
                userId: $orderModel-&gt;user_id,
                items: array_map(
                    fn ($item) =&gt; new OrderItem(
                        productId: $item-&gt;product_id,
                        quantity: $item-&gt;quantity,
                        unitPrice: $item-&gt;unit_price,
                    ),
                    $orderModel-&gt;items()-&gt;get()-&gt;all()
                ),
                status: $orderModel-&gt;status,
            );
        });
    }

    public function findById(int $id): ?Order
    {
        \(model = OrderModel::with('items')-&gt;find(\)id);

        if (! $model) {
            return null;
        }

        return new Order(
            id: $model-&gt;id,
            userId: $model-&gt;user_id,
            items: array_map(
                fn ($item) =&gt; new OrderItem(
                    productId: $item-&gt;product_id,
                    quantity: $item-&gt;quantity,
                    unitPrice: $item-&gt;unit_price,
                ),
                $model-&gt;items-&gt;all()
            ),
            status: $model-&gt;status,
        );
    }
}
</code></pre>
<h3>9.3 Inventory Stock Repository</h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Inventory\Infrastructure\Persistence\Eloquent\Repositories;

use App\Modules\Inventory\Domain\Repositories\ProductStockRepositoryInterface;
use App\Modules\Inventory\Infrastructure\Persistence\Eloquent\Models\ProductStockModel;

class EloquentProductStockRepository implements ProductStockRepositoryInterface
{
    public function getAvailableQuantity(int $productId): int
    {
        \(stock = ProductStockModel::where('product_id', \)productId)-&gt;first();

        return $stock?-&gt;available_quantity ?? 0;
    }

    public function decrement(int \(productId, int \)quantity): void
    {
        \(stock = ProductStockModel::where('product_id', \)productId)-&gt;firstOrFail();

        \(stock-&gt;decrement('available_quantity', \)quantity);
    }
}
</code></pre>
<h2>10. Presentation Layer</h2>
<h3>10.1 Request Validation</h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Presentation\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class PlaceOrderRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'user_id' =&gt; ['required', 'integer'],
            'items' =&gt; ['required', 'array', 'min:1'],
            'items.*.product_id' =&gt; ['required', 'integer'],
            'items.*.quantity' =&gt; ['required', 'integer', 'min:1'],
            'items.*.unit_price' =&gt; ['required', 'integer', 'min:1'],
        ];
    }
}
</code></pre>
<h3>10.2 Controller</h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Presentation\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Orders\Application\DTOs\PlaceOrderCommand;
use App\Modules\Orders\Application\UseCases\PlaceOrder;
use App\Modules\Orders\Presentation\Http\Requests\PlaceOrderRequest;
use App\Modules\Orders\Presentation\Http\Resources\OrderResource;
use Illuminate\Http\JsonResponse;

class OrderController extends Controller
{
    public function store(
        PlaceOrderRequest $request,
        PlaceOrder $placeOrder,
    ): JsonResponse {
        $command = new PlaceOrderCommand(
            userId: $request-&gt;integer('user_id'),
            items: $request-&gt;input('items'),
        );

        \(order = \)placeOrder-&gt;execute($command);

        return response()-&gt;json([
            'data' =&gt; (new OrderResource(\(order))-&gt;toArray(\)request),
        ], 201);
    }
}
</code></pre>
<h3>10.3 Resource</h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Presentation\Http\Resources;

use App\Modules\Orders\Domain\Entities\Order;
use App\Modules\Orders\Domain\Entities\OrderItem;

class OrderResource
{
    public function __construct(
        private Order $order
    ) {}

    public function toArray($request): array
    {
        return [
            'id' =&gt; $this-&gt;order-&gt;getId(),
            'user_id' =&gt; $this-&gt;order-&gt;getUserId(),
            'status' =&gt; $this-&gt;order-&gt;getStatus(),
            'items' =&gt; array_map(
                fn (OrderItem $item) =&gt; [
                    'product_id' =&gt; $item-&gt;getProductId(),
                    'quantity' =&gt; $item-&gt;getQuantity(),
                    'unit_price' =&gt; $item-&gt;getUnitPrice(),
                    'subtotal' =&gt; $item-&gt;getSubtotal(),
                ],
                $this-&gt;order-&gt;getItems()
            ),
        ];
    }
}
</code></pre>
<h3>10.4 Module Route File</h3>
<pre><code class="language-php">&lt;?php

use Illuminate\Support\Facades\Route;
use App\Modules\Orders\Presentation\Http\Controllers\OrderController;

Route::prefix('orders')-&gt;group(function () {
    Route::post('/', [OrderController::class, 'store']);
});
</code></pre>
<h2>11. Service Providers and Dependency Injection</h2>
<h3>11.1 Orders Service Provider</h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Orders\Infrastructure\Providers;

use Illuminate\Support\ServiceProvider;
use App\Modules\Orders\Domain\Repositories\OrderRepositoryInterface;
use App\Modules\Orders\Domain\Services\InventoryGatewayInterface;
use App\Modules\Orders\Infrastructure\Persistence\Eloquent\Repositories\EloquentOrderRepository;
use App\Modules\Inventory\Infrastructure\Services\StockReservationService;

class OrdersServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this-&gt;app-&gt;bind(OrderRepositoryInterface::class, EloquentOrderRepository::class);
        $this-&gt;app-&gt;bind(InventoryGatewayInterface::class, StockReservationService::class);
    }

    public function boot(): void
    {
        $this-&gt;loadRoutesFrom(app_path('Modules/Orders/Presentation/Routes/api.php'));
        $this-&gt;loadMigrationsFrom(app_path('Modules/Orders/Database/Migrations'));
    }
}
</code></pre>
<h3>11.2 Inventory Service Provider</h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Inventory\Infrastructure\Providers;

use Illuminate\Support\ServiceProvider;
use App\Modules\Inventory\Domain\Repositories\ProductStockRepositoryInterface;
use App\Modules\Inventory\Infrastructure\Persistence\Eloquent\Repositories\EloquentProductStockRepository;

class InventoryServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this-&gt;app-&gt;bind(
            ProductStockRepositoryInterface::class,
            EloquentProductStockRepository::class
        );
    }

    public function boot(): void
    {
        $this-&gt;loadMigrationsFrom(app_path('Modules/Inventory/Database/Migrations'));
    }
}
</code></pre>
<h3>Why this matters</h3>
<p>This is what makes the architecture real:</p>
<ul>
<li>the use case depends on interfaces</li>
<li>the container provides implementations</li>
<li>modules remain replaceable behind contracts</li>
</ul>
<h2>12. Database Migrations</h2>
<h3>12.1 Orders Table</h3>
<pre><code class="language-php">&lt;?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        Schema::create('orders', function (Blueprint $table) {
            $table-&gt;id();
            $table-&gt;unsignedBigInteger('user_id');
            $table-&gt;string('status');
            $table-&gt;timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('orders');
    }
};
</code></pre>
<h3>12.2 Order Items Table</h3>
<pre><code class="language-php">&lt;?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        Schema::create('order_items', function (Blueprint $table) {
            $table-&gt;id();
            $table-&gt;foreignId('order_id')-&gt;constrained('orders')-&gt;cascadeOnDelete();
            $table-&gt;unsignedBigInteger('product_id');
            $table-&gt;integer('quantity');
            $table-&gt;integer('unit_price');
            $table-&gt;timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('order_items');
    }
};
</code></pre>
<h3>12.3 Product Stocks Table</h3>
<pre><code class="language-php">&lt;?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        Schema::create('product_stocks', function (Blueprint $table) {
            $table-&gt;id();
            $table-&gt;unsignedBigInteger('product_id')-&gt;unique();
            $table-&gt;integer('available_quantity')-&gt;default(0);
            $table-&gt;timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('product_stocks');
    }
};
</code></pre>
<h2>13. Shared Folder: What It Is For</h2>
<p>The <code>Shared</code> folder is for things that are:</p>
<ul>
<li>generic</li>
<li>reusable across modules</li>
<li>not owned by one business module</li>
</ul>
<p>Good examples:</p>
<ul>
<li><code>Money</code></li>
<li><code>Email</code></li>
<li><code>ClockInterface</code></li>
<li><code>IdGeneratorInterface</code></li>
</ul>
<p>Bad examples:</p>
<ul>
<li><code>OrderHelper</code></li>
<li><code>BillingCommon</code></li>
<li><code>InventoryUtils</code></li>
<li>feature-specific services moved to shared just because two modules use them</li>
</ul>
<h3>Example Shared Value Object</h3>
<pre><code class="language-php">&lt;?php

namespace App\Modules\Shared\Domain\ValueObjects;

final class Money
{
    public function __construct(
        private int $amount,
        private string $currency = 'USD'
    ) {}

    public function add(Money $other): Money
    {
        if (\(this-&gt;currency !== \)other-&gt;currency) {
            throw new \InvalidArgumentException('Currency mismatch');
        }

        return new Money(\(this-&gt;amount + \)other-&gt;amount, $this-&gt;currency);
    }

    public function amount(): int
    {
        return $this-&gt;amount;
    }

    public function currency(): string
    {
        return $this-&gt;currency;
    }
}
</code></pre>
<h2>14. Request Flow Summary</h2>
<p>For <code>POST /orders</code>:</p>
<ol>
<li><code>OrderController</code> receives the request</li>
<li><code>PlaceOrderRequest</code> validates input</li>
<li>Controller creates <code>PlaceOrderCommand</code></li>
<li><code>PlaceOrder</code> use case executes</li>
<li>Use case builds domain <code>Order</code> and <code>OrderItem</code></li>
<li>Use case calls <code>InventoryGatewayInterface</code></li>
<li>Laravel resolves it to <code>StockReservationService</code></li>
<li>Inventory reserves stock</li>
<li>Orders repository persists the order</li>
<li>Resource returns JSON response</li>
</ol>
<p>This is a modular monolith because the whole flow runs inside one Laravel app.</p>
<p>This is clean architecture because the business flow does not depend on framework details.</p>
<h2>15. What Not to Do</h2>
<h3>Bad: Use Eloquent directly in the use case</h3>
<pre><code class="language-php">$order = OrderModel::create([...]);
</code></pre>
<p>This makes the application layer depend on Laravel ORM.</p>
<h3>Bad: Access another module's internal models</h3>
<pre><code class="language-php">ProductStockModel::where('product_id', $id)-&gt;decrement(...);
</code></pre>
<p>This breaks module boundaries because Orders is now touching Inventory internals.</p>
<h3>Bad: Put business logic in controllers</h3>
<pre><code class="language-php">foreach (\(request-&gt;items as \)item) {
    // reserve stock
    // calculate total
    // create order
}
</code></pre>
<p>Controllers should adapt HTTP, not implement business rules.</p>
<h2>16. Recommended Practical Rules</h2>
<p>For a real Laravel modular monolith:</p>
<ul>
<li>keep <strong>Domain</strong> pure PHP</li>
<li>keep <strong>Application</strong> focused on use cases</li>
<li>keep <strong>Infrastructure</strong> responsible for Eloquent and framework integration</li>
<li>keep <strong>Presentation</strong> thin</li>
<li>let modules talk through interfaces</li>
<li>keep <code>Shared</code> small and disciplined</li>
<li>place migrations inside modules and load them through service providers</li>
</ul>
<h2>17. Final Takeaway</h2>
<p>A clean modular monolith should let you say:</p>
<ul>
<li><strong>Orders can be understood mostly by reading the Orders module</strong></li>
<li><strong>Inventory can change its persistence internals without breaking Orders</strong></li>
<li><strong>Business rules do not depend on Laravel controllers or Eloquent</strong></li>
</ul>
<p>If those are true, the architecture is in a good place.</p>
]]></content:encoded></item><item><title><![CDATA[Troubleshooting Valet: Making Hidden Sites For Invisible In Valet-Sites.]]></title><description><![CDATA[Valet sites display the folders you want to access. The default folder is www in your user folder (/home/username/www) also valet parks some folders but does not show in valet sites.
<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">...]]></description><link>https://blog.shazeedul.dev/troubleshooting-valet-making-hidden-sites-for-invisible-in-valet-sites</link><guid isPermaLink="true">https://blog.shazeedul.dev/troubleshooting-valet-making-hidden-sites-for-invisible-in-valet-sites</guid><category><![CDATA[valet]]></category><category><![CDATA[Linux]]></category><dc:creator><![CDATA[Syed Shazeedul Islam]]></dc:creator><pubDate>Mon, 20 Jan 2025 05:21:31 GMT</pubDate><content:encoded><![CDATA[<p>Valet sites display the folders you want to access. The default folder is www in your user folder (/home/username/www) also valet parks some folders but does not show in valet sites.</p>
<pre><code class="lang-xml"><span class="hljs-meta">&lt;!doctype <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"ie=edge"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Valet Sites<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
        <span class="hljs-selector-tag">html</span>,
        <span class="hljs-selector-tag">body</span> {
            <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
            <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
            <span class="hljs-attribute">font-family</span>: monospace, sans-serif;
            <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.45</span>;
            <span class="hljs-attribute">font-size</span>: <span class="hljs-number">16px</span>;
            <span class="hljs-attribute">letter-spacing</span>: <span class="hljs-number">0</span>;
            <span class="hljs-attribute">position</span>: relative;
        }

        <span class="hljs-selector-tag">ul</span> {
            <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
            <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
            <span class="hljs-attribute">list-style</span>: none;
            <span class="hljs-attribute">text-align</span>: center;
        }

        <span class="hljs-selector-tag">ul</span>&gt;<span class="hljs-selector-tag">li</span> {
            <span class="hljs-attribute">display</span>: inline-block;
            <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span> <span class="hljs-number">5px</span>;
        }

        <span class="hljs-selector-tag">ul</span>&gt;<span class="hljs-selector-tag">li</span>&gt;<span class="hljs-selector-tag">a</span> {
            <span class="hljs-attribute">text-decoration</span>: none;
            <span class="hljs-attribute">padding</span>: <span class="hljs-number">15px</span> <span class="hljs-number">30px</span>;
            <span class="hljs-attribute">display</span>: block;
            <span class="hljs-attribute">text-transform</span>: capitalize;
            <span class="hljs-attribute">color</span>: <span class="hljs-number">#2d2d2d</span>;
            <span class="hljs-attribute">text-align</span>: center;
            <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-built_in">rgba</span>(<span class="hljs-number">51</span>, <span class="hljs-number">51</span>, <span class="hljs-number">51</span>, <span class="hljs-number">0.25</span>);
            <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">2px</span> <span class="hljs-number">2px</span> <span class="hljs-number">5px</span> <span class="hljs-number">#d4d4d4</span>;
            <span class="hljs-attribute">transition</span>: all .<span class="hljs-number">15s</span> linear;
        }

        <span class="hljs-selector-tag">ul</span>&gt;<span class="hljs-selector-tag">li</span>&gt;<span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span> {
            <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">1px</span> <span class="hljs-number">1px</span> <span class="hljs-number">3px</span> <span class="hljs-number">#d4d4d4</span>;
        }

        <span class="hljs-selector-tag">ul</span>&gt;<span class="hljs-selector-tag">li</span>&gt;<span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:visited</span> {
            <span class="hljs-attribute">color</span>: <span class="hljs-number">#0042bd</span>;
            <span class="hljs-attribute">border-color</span>: <span class="hljs-number">#0042bd</span>;
        }

        <span class="hljs-selector-tag">ul</span>&gt;<span class="hljs-selector-tag">li</span>&gt;<span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:before</span> {
            <span class="hljs-attribute">content</span>: <span class="hljs-string">""</span>;
            <span class="hljs-attribute">height</span>: <span class="hljs-number">50px</span>;
            <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
            <span class="hljs-attribute">display</span>: inline-block;
            <span class="hljs-attribute">text-align</span>: center;
            <span class="hljs-attribute">background</span>: <span class="hljs-built_in">url</span>(<span class="hljs-string">'image path or base64'</span>);
            <span class="hljs-attribute">background-size</span>: <span class="hljs-number">50px</span> <span class="hljs-number">50px</span>;
            <span class="hljs-attribute">background-repeat</span>: no-repeat;
            <span class="hljs-attribute">background-position</span>: center center;
        }

        <span class="hljs-selector-tag">h1</span> {
            <span class="hljs-attribute">text-align</span>: center;
            <span class="hljs-attribute">margin</span>: <span class="hljs-number">15px</span> <span class="hljs-number">0</span> <span class="hljs-number">15px</span>;
            <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#ccc</span>;
            <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.6</span>;
            <span class="hljs-attribute">padding</span>: <span class="hljs-number">0px</span> <span class="hljs-number">0</span> <span class="hljs-number">10px</span>;
        }

        <span class="hljs-keyword">@media</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">767px</span>) {
            <span class="hljs-selector-tag">h1</span> {
                <span class="hljs-attribute">font-size</span>: <span class="hljs-number">25px</span>;
            }

            <span class="hljs-selector-tag">ul</span>&gt;<span class="hljs-selector-tag">li</span>&gt;<span class="hljs-selector-tag">a</span> {
                <span class="hljs-attribute">padding</span>: <span class="hljs-number">5px</span> <span class="hljs-number">15px</span>;
            }
        }

        <span class="hljs-keyword">@media</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">479px</span>) {
            <span class="hljs-selector-tag">h1</span> {
                <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>;
            }
        }
    </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Valet Available Sites<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">?php</span> <span class="hljs-attr">if</span> (<span class="hljs-attr">isset</span>($<span class="hljs-attr">availableSites</span>)) { ?&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">?php</span>
            <span class="hljs-attr">foreach</span> ($<span class="hljs-attr">availableSites</span> <span class="hljs-attr">as</span> $<span class="hljs-attr">sitePath</span> =&gt;</span> $availableSite) {
                echo "<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">'/valet-sites?use={$sitePath}'</span>&gt;</span>{$availableSite}<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>";
            }
            ?&gt;
        <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">?php</span> } ?&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>So how to get available sites to show?</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
    $directory = <span class="hljs-string">'/home/shazeedul/www'</span>; <span class="hljs-comment">// Replace with the path to your directory</span>
    <span class="hljs-keyword">if</span> (is_dir($directory)) {
        $files = scandir($directory);
        <span class="hljs-comment">// filter only directories</span>
        $sites          = array_filter($files, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">$file</span>) <span class="hljs-title">use</span> (<span class="hljs-params">$directory</span>) </span>{
            <span class="hljs-keyword">return</span> is_dir($directory . <span class="hljs-string">'/'</span> . $file) &amp;&amp; !in_array($file, [<span class="hljs-string">'.'</span>, <span class="hljs-string">'..'</span>, <span class="hljs-string">'.git'</span>]);
        });
        $availableSites = [];
        <span class="hljs-keyword">foreach</span> ($sites <span class="hljs-keyword">as</span> $key =&gt; $site) {
            $key                  = strtolower(str_replace(<span class="hljs-string">' '</span>, <span class="hljs-string">'-'</span>, $site));
            $availableSites[$key] = ucwords(str_replace(<span class="hljs-string">'-'</span>, <span class="hljs-string">' '</span>, $site));
        }
    } <span class="hljs-keyword">else</span> {
        $availableSites = [];
    }
<span class="hljs-meta">?&gt;</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[How to Configure Tenancy for Laravel Using the Modules Package]]></title><description><![CDATA[First, install Laravel fresh project or pick your existing project where already has nwidart/laravel-modules.
If you haven’t install any Laravel project then let’s start and explore it -
composer create-project laravel/laravel:^10.0 example-app

Now ...]]></description><link>https://blog.shazeedul.dev/how-to-configure-tenancy-for-laravel-using-the-modules-package</link><guid isPermaLink="true">https://blog.shazeedul.dev/how-to-configure-tenancy-for-laravel-using-the-modules-package</guid><category><![CDATA[tenancy-for-laravel]]></category><category><![CDATA[laravel-modules]]></category><category><![CDATA[Multi tenancy]]></category><category><![CDATA[Laravel]]></category><category><![CDATA[PHP]]></category><dc:creator><![CDATA[Syed Shazeedul Islam]]></dc:creator><pubDate>Tue, 03 Dec 2024 08:24:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1733214085285/78f1704c-168e-4f2f-9bb1-525077d29860.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>First, install Laravel fresh project or pick your existing project where already has <a target="_blank" href="https://nwidart.com/laravel-modules/v6/introduction">nwidart/laravel-modules</a>.</p>
<p>If you haven’t install any <a target="_blank" href="https://laravel.com/docs/10.x">Laravel</a> project then let’s start and explore it -</p>
<pre><code class="lang-bash">composer create-project laravel/laravel:^10.0 example-app
</code></pre>
<p>Now integrate Laravel Modules Package -</p>
<pre><code class="lang-bash">composer require nwidart/laravel-modules
</code></pre>
<p>Also, integrate Tenancy for Laravel Package -</p>
<pre><code class="lang-bash">composer require stancl/tenancy
</code></pre>
<pre><code class="lang-bash">php artisan tenancy:install
</code></pre>
<pre><code class="lang-bash">// bootstrap/providers.php
<span class="hljs-built_in">return</span> [
    App\Providers\AppServiceProvider::class,
    App\Providers\TenancyServiceProvider::class, // &lt;-- here
];
</code></pre>
<p>First Configure all requirements for tenancy from <a target="_blank" href="https://tenancyforlaravel.com/docs/v3/installation">Tenancy Docs</a>. After preparing tenancy in the project create a fresh module like Blog -</p>
<pre><code class="lang-php">php artisan module:make Blog
</code></pre>
<p>After creating a fresh Blog module there are all the essential files for Laravel app. Now we want to modify this for our tenant setup.</p>
<p>Well, first, we’re going to configure migrations for the tenant in the Modules/Blog/Database/migrations path. In this path, all migrations are for the central system. Now, create a tenant folder in that folder, like (Modules/Blog/Database/migrations/tenant), and configure it on the service provider. For this feature, we want a service provider, so create a service provider in the Blog Module.</p>
<pre><code class="lang-php">php artisan module:make-provider TenantBlogServiceProvider Blog
</code></pre>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">Modules</span>\<span class="hljs-title">Blog</span>\<span class="hljs-title">App</span>\<span class="hljs-title">Providers</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">ServiceProvider</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">TenantBlogServiceProvider</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">ServiceProvider</span>
</span>{
    <span class="hljs-comment">/**
     * Register the service provider.
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">register</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span>
    </span>{
        <span class="hljs-comment">// Register module tenant migrations</span>
        <span class="hljs-keyword">$this</span>-&gt;app-&gt;booted(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            config()-&gt;push(
                <span class="hljs-string">'tenancy.migration_parameters.--path'</span>,
                module_path(<span class="hljs-string">'Blog'</span>, <span class="hljs-string">'Database/migrations/tenant'</span>)
            );
        });
    }

    <span class="hljs-comment">/**
     * Get the services provided by the provider.
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">provides</span>(<span class="hljs-params"></span>): <span class="hljs-title">array</span>
    </span>{
        <span class="hljs-keyword">return</span> [];
    }
}
</code></pre>
<p>Register the provider in the BlogServiceProvider.php file</p>
<pre><code class="lang-php"><span class="hljs-comment">/**
 * Register the service provider.
*/</span>
<span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">register</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span>
</span>{
    <span class="hljs-keyword">$this</span>-&gt;app-&gt;register(RouteServiceProvider::class);
    <span class="hljs-keyword">$this</span>-&gt;app-&gt;register(TenantBlogServiceProvider::class); <span class="hljs-comment">// Register tenant service provider for this module</span>
}
</code></pre>
<p>Now we’re going to config routes for tenants -</p>
<p>We know all routes are web.php for web guard and api.php for API guard. But for central system routes boundary we should configure RouteServiceProvider in Blog Module -</p>
<pre><code class="lang-php">    <span class="hljs-comment">/**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mapWebRoutes</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span>
    </span>{
        <span class="hljs-keyword">foreach</span> (<span class="hljs-keyword">$this</span>-&gt;centralDomains() <span class="hljs-keyword">as</span> $domain) {
            Route::middleware(<span class="hljs-string">'web'</span>)
                -&gt;namespace(<span class="hljs-keyword">$this</span>-&gt;moduleNamespace)
                -&gt;domain($domain)
                -&gt;group(module_path(<span class="hljs-string">'Blog'</span>, <span class="hljs-string">'/routes/web.php'</span>));
        }
    }

    <span class="hljs-comment">/**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mapApiRoutes</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span>
    </span>{
        <span class="hljs-keyword">foreach</span> (<span class="hljs-keyword">$this</span>-&gt;centralDomains() <span class="hljs-keyword">as</span> $domain) {
            Route::prefix(<span class="hljs-string">'api'</span>)
                -&gt;middleware(<span class="hljs-string">'api'</span>)
                -&gt;namespace(<span class="hljs-keyword">$this</span>-&gt;moduleNamespace)
                -&gt;domain($domain)
                -&gt;group(module_path(<span class="hljs-string">'Blog'</span>, <span class="hljs-string">'/routes/api.php'</span>));
        }
    }

    <span class="hljs-comment">/**
     * Define the "tenant" routes for the application.
     * 
     * These routes are typically stateless.
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mapTenantRoutes</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span>
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;app-&gt;booted(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            <span class="hljs-keyword">if</span> (file_exists(module_path(<span class="hljs-string">'Blog'</span>, <span class="hljs-string">'/routes/tenant.php'</span>))) {
                Route::namespace(<span class="hljs-keyword">$this</span>-&gt;moduleNamespace)
                    -&gt;group(module_path(<span class="hljs-string">'Blog'</span>, <span class="hljs-string">'/routes/tenant.php'</span>));
            }
        });
    }

    <span class="hljs-comment">/**
     * Define the routes for the application.
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">centralDomains</span>(<span class="hljs-params"></span>): <span class="hljs-title">array</span>
    </span>{
        <span class="hljs-keyword">return</span> config(<span class="hljs-string">'tenancy.central_domains'</span>);
    }
</code></pre>
<p>Finally RouteServiceProvider.php for Blog Module</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">Modules</span>\<span class="hljs-title">Blog</span>\<span class="hljs-title">App</span>\<span class="hljs-title">Providers</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Route</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Foundation</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Providers</span>\<span class="hljs-title">RouteServiceProvider</span> <span class="hljs-title">as</span> <span class="hljs-title">ServiceProvider</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RouteServiceProvider</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">ServiceProvider</span>
</span>{
    <span class="hljs-comment">/**
     * The module namespace to assume when generating URLs to actions.
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">string</span> $moduleNamespace = <span class="hljs-string">'Modules\Blog\App\Http\Controllers'</span>;

    <span class="hljs-comment">/**
     * Called before routes are registered.
     *
     * Register any model bindings or pattern based filters.
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">boot</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span>
    </span>{
        <span class="hljs-built_in">parent</span>::boot();
    }

    <span class="hljs-comment">/**
     * Define the routes for the application.
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">map</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span>
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;mapApiRoutes();

        <span class="hljs-keyword">$this</span>-&gt;mapWebRoutes();

        <span class="hljs-comment">// Register tenant routes</span>
        <span class="hljs-keyword">$this</span>-&gt;mapTenantRoutes();
    }

    <span class="hljs-comment">/**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mapWebRoutes</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span>
    </span>{
        <span class="hljs-keyword">foreach</span> (<span class="hljs-keyword">$this</span>-&gt;centralDomains() <span class="hljs-keyword">as</span> $domain) {
            Route::middleware(<span class="hljs-string">'web'</span>)
                -&gt;namespace(<span class="hljs-keyword">$this</span>-&gt;moduleNamespace)
                -&gt;domain($domain)
                -&gt;group(module_path(<span class="hljs-string">'Blog'</span>, <span class="hljs-string">'/routes/web.php'</span>));
        }
    }

    <span class="hljs-comment">/**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mapApiRoutes</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span>
    </span>{
        <span class="hljs-keyword">foreach</span> (<span class="hljs-keyword">$this</span>-&gt;centralDomains() <span class="hljs-keyword">as</span> $domain) {
            Route::prefix(<span class="hljs-string">'api'</span>)
                -&gt;middleware(<span class="hljs-string">'api'</span>)
                -&gt;namespace(<span class="hljs-keyword">$this</span>-&gt;moduleNamespace)
                -&gt;domain($domain)
                -&gt;group(module_path(<span class="hljs-string">'Blog'</span>, <span class="hljs-string">'/routes/api.php'</span>));
        }
    }

    <span class="hljs-comment">/**
     * Define the "tenant" routes for the application.
     * 
     * These routes are typically stateless.
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mapTenantRoutes</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span>
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;app-&gt;booted(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            <span class="hljs-keyword">if</span> (file_exists(module_path(<span class="hljs-string">'Blog'</span>, <span class="hljs-string">'/routes/tenant.php'</span>))) {
                Route::namespace(<span class="hljs-keyword">$this</span>-&gt;moduleNamespace)
                    -&gt;group(module_path(<span class="hljs-string">'Blog'</span>, <span class="hljs-string">'/routes/tenant.php'</span>));
            }
        });
    }

    <span class="hljs-comment">/**
     * Define the routes for the application.
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">centralDomains</span>(<span class="hljs-params"></span>): <span class="hljs-title">array</span>
    </span>{
        <span class="hljs-keyword">return</span> config(<span class="hljs-string">'tenancy.central_domains'</span>);
    }
}
</code></pre>
<p>Now try it after the composer dump-autoload command.</p>
<pre><code class="lang-php">php artisan route:<span class="hljs-keyword">list</span>
php artisan serve
</code></pre>
]]></content:encoded></item><item><title><![CDATA[A Beginner's Guide to Golang: An Introduction]]></title><description><![CDATA[What is Go?
Go is a statically typed, open-source, compiled programming language. We are known for greater efficiency in speed, performance, and usability.
The above brief introduction may not be straightforward. So let's break down the definition a ...]]></description><link>https://blog.shazeedul.dev/beginners-guide-to-golang-an-introduction</link><guid isPermaLink="true">https://blog.shazeedul.dev/beginners-guide-to-golang-an-introduction</guid><category><![CDATA[golang]]></category><category><![CDATA[Go Language]]></category><category><![CDATA[Go]]></category><dc:creator><![CDATA[Syed Shazeedul Islam]]></dc:creator><pubDate>Tue, 22 Oct 2024 08:39:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1729583240816/dc2c6fdf-8691-43e6-ad81-a3381c430521.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-what-is-go">What is Go?</h2>
<p>Go is a statically typed, open-source, compiled programming language. We are known for greater efficiency in speed, performance, and usability.</p>
<p>The above brief introduction may not be straightforward. So let's break down the definition a bit -</p>
<ul>
<li><p><code>First, let's talk about “statically typed”. Statically typed means that the data type of all variables used in Go is determined at compile time before runtime. That is, the data type is determined before the program is run.</code></p>
</li>
<li><p><code>Then comes, “Open Source”. Due to its open-source nature, anyone can create packages for any task, and since Go is a package-based language, Go's community support can contribute directly.</code></p>
</li>
<li><p><code>"Compiled" means that all Go code is directly converted to machine code and can be run directly on a computer's processor. Go performs better than other interpreted languages ​​(JavaScript, Python) for this feature.</code></p>
</li>
</ul>
<h2 id="heading-usage-of-go">Usage of Go</h2>
<ul>
<li><p>For building any web application, web servers, APIs, and today's most popular microservices architecture.</p>
</li>
<li><p>For system software, such as operating systems, device drivers, and network protocols.</p>
</li>
<li><p>Go has its own concurrency support for distributed systems, data pipelining, and streaming applications.</p>
</li>
<li><p>For network applications like servers, proxies, and load balancers.</p>
</li>
<li><p>For various DevOps and cloud applications.</p>
</li>
</ul>
<h2 id="heading-go-install">Go Install</h2>
<p>We chose VS code as the IDE to start our Go journey, as it is one of the most widely used IDEs and is open source.</p>
<p>The process of installing Go is slightly different depending on the platform. For now, we are only providing guidelines for installing Go on Windows.</p>
<p><code>Install Go on Windows –</code></p>
<ul>
<li><p>First, download the .msi file for Windows from this link.</p>
</li>
<li><p>Once the file is downloaded, open it and follow the prompts-</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729584207816/f2b9363b-b126-4385-8426-66118a1c8084.png" alt class="image--center mx-auto" /></p>
<ul>
<li>First, after waiting for a while, I will click on the Next button.</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729584257750/5a11d5b7-3956-4a83-8801-a17187f9deb8.png" alt class="image--center mx-auto" /></p>
<ul>
<li>Then click on the Next button again.</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729584436791/ef02b9ca-064c-4381-b08b-9a58cefe77c1.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>We can choose any directory we want, but now we will select the default directory and click Next button again.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729585237602/daad4317-d1ce-4253-ae2b-aa4026a38804.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>If you click on the Install button, Windows administrative will ask for permission, then click on the Yes button.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729585301976/5225e905-9805-4219-94be-e6c0ec8514be.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>When the installation is finished, we will click on the Finish button.</p>
</li>
<li><p>To check whether it is installed correctly, open the command prompt and run the go version command, then we will see something like the image. Congratulations, Go has been successfully installed on your system.</p>
</li>
</ul>
<h2 id="heading-install-go-on-linux">Install Go on Linux –</h2>
<ul>
<li><p>First of all, I will download the Linux binary release file by going to this link.</p>
</li>
<li><p>If any version of Go is already installed on the system then remove it from the system by running the following command –</p>
</li>
</ul>
<pre><code class="lang-bash">sudo rm -rf /usr/<span class="hljs-built_in">local</span>/go
</code></pre>
<ul>
<li>Then extract the downloaded file to /usr/local location –</li>
</ul>
<pre><code class="lang-bash">sudo tar -C /usr/<span class="hljs-built_in">local</span> -xzf gox.x.x.linux-amd64.tar.gz
</code></pre>
<ul>
<li>Add /usr/local/Go/bin to PATH environment variable –</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-built_in">export</span> PATH=<span class="hljs-variable">$PATH</span>:/usr/<span class="hljs-built_in">local</span>/go/bin
</code></pre>
<ul>
<li><p>Log-out once and log in again.</p>
</li>
<li><p>By opening the terminal and running the following command, if we see the version of Go, then we will understand that our installation process has been completed properly –</p>
</li>
</ul>
<pre><code class="lang-bash">go version
</code></pre>
<h2 id="heading-the-first-program-in-go">The first program in Go -</h2>
<p>When starting to learn a language, our first task is to run a program before we learn something well, with which we can say "Hello World!" to the terminal. I can print the output. Then, without delay, fulfill that responsibility -</p>
<ul>
<li>First, create a directory and open it with vs code –</li>
</ul>
<pre><code class="lang-bash">&gt; mkdir hello-world
&gt; <span class="hljs-built_in">cd</span> hello-world
&gt; code .
</code></pre>
<p>main.go</p>
<pre><code class="lang-bash">package main

import <span class="hljs-string">"fmt"</span>

func <span class="hljs-function"><span class="hljs-title">main</span></span>() {
    fmt.Println(<span class="hljs-string">"Hello World!"</span>)
}
</code></pre>
<ul>
<li><p>The entry point of any Go program is its main() function. That is, a Go program must have func main().</p>
</li>
<li><p>Inside the main() function, Println is a function of the fmt package. Go is a package based language. Since we have used the fmt package here, we have to import it. And by using this Println() function we can print “Hello World!” in the terminal.</p>
</li>
<li><p>To run the above program, we will run the following command from the terminal –</p>
</li>
</ul>
<pre><code class="lang-bash">go run main.go
</code></pre>
<ul>
<li><p>This will build and run the program together and we will see “Hello World!” in the terminal. I will get the output.</p>
</li>
<li><p>If we want to save the program as an executable binary only, then run the following command –</p>
</li>
</ul>
<pre><code class="lang-bash">go build main.go
</code></pre>
]]></content:encoded></item><item><title><![CDATA[50 basic Linux commands]]></title><description><![CDATA[𝐄𝐬𝐬𝐞𝐧𝐭𝐢𝐚𝐥 𝟓𝟎 𝐁𝐚𝐬𝐢𝐜 𝐋𝐢𝐧𝐮𝐱 𝐂𝐨𝐦𝐦𝐚𝐧𝐝𝐬: 𝐌𝐚𝐬𝐭𝐞𝐫 𝐘𝐨𝐮𝐫 𝐂𝐨𝐦𝐦𝐚𝐧𝐝 𝐋𝐢𝐧𝐞 𝐒𝐤𝐢𝐥𝐥𝐬 🐧
𝐩𝐰𝐝 - Print working directory. 📂𝐥𝐬 - List directory contents. 📋𝐜𝐝 - Change directory. 📁𝐭𝐨𝐮𝐜𝐡 - To create a fi...]]></description><link>https://blog.shazeedul.dev/50-basic-linux-commands</link><guid isPermaLink="true">https://blog.shazeedul.dev/50-basic-linux-commands</guid><category><![CDATA[Linux]]></category><category><![CDATA[Bash]]></category><category><![CDATA[LinuxTips]]></category><category><![CDATA[#linuxTutorial]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Syed Shazeedul Islam]]></dc:creator><pubDate>Mon, 15 Jul 2024 05:48:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/xbEVM6oJ1Fs/upload/5b958d445b0c5ce4e75ad344bf323ab7.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>𝐄𝐬𝐬𝐞𝐧𝐭𝐢𝐚𝐥 𝟓𝟎 𝐁𝐚𝐬𝐢𝐜 𝐋𝐢𝐧𝐮𝐱 𝐂𝐨𝐦𝐦𝐚𝐧𝐝𝐬: 𝐌𝐚𝐬𝐭𝐞𝐫 𝐘𝐨𝐮𝐫 𝐂𝐨𝐦𝐦𝐚𝐧𝐝 𝐋𝐢𝐧𝐞 𝐒𝐤𝐢𝐥𝐥𝐬 🐧</p>
<p>𝐩𝐰𝐝 - Print working directory. 📂<br />𝐥𝐬 - List directory contents. 📋<br />𝐜𝐝 - Change directory. 📁<br />𝐭𝐨𝐮𝐜𝐡 - To create a file without any content. 📄<br />𝐜𝐚𝐭 - Concatenate and display file content. 🐱<br />𝐜𝐩 - Copy files or directories. 📁📂<br />𝐦𝐯 - Move or rename files or directories. 🔄<br />𝐫𝐦 - Remove files or directories. 🗑️<br />𝐦𝐤𝐝𝐢𝐫 - Create a new directory. 📁<br />𝐫𝐦𝐝𝐢𝐫 - Remove an empty directory. 📁🗑️<br />𝐞𝐜𝐡𝐨 - Display a line of text or a variable value. 📢<br />𝐧𝐚𝐧𝐨 - A simple text editor. ✏️<br />𝐯𝐢 - A powerful text editor. ✒️<br />𝐜𝐡𝐦𝐨𝐝 - Change file or directory permissions. 🔐<br />𝐜𝐡𝐨𝐰𝐧 - Change file or directory owner and group. 👤<br />𝐟𝐢𝐧𝐝 - Search for files in a directory hierarchy. 🔍<br />𝐠𝐫𝐞𝐩 - Search text using patterns. 🔎<br />𝐦𝐚𝐧 - Display the manual for a command. 📖<br />𝐩𝐬 - Display information about running processes. 🔄<br />𝐤𝐢𝐥𝐥 - Terminate processes by PID. ⚰️<br />𝐭𝐨𝐩 - Display and update sorted information about processes. 📊<br />𝐝𝐟 - Report file system disk space usage. 💾<br />𝐝𝐮 - Estimate file space usage. 📏<br />𝐟𝐫𝐞𝐞 - Display memory usage. 🧠<br />𝐮𝐧𝐚𝐦𝐞 - Print system information. ℹ️<br />𝐮𝐩𝐭𝐢𝐦𝐞 - Tell how long the system has been running. ⏳<br />𝐰𝐡𝐨𝐚𝐦𝐢 - Display the current user. 👤<br />𝐬𝐮𝐝𝐨 - Execute a command as another user, typically the superuser. 🛡️<br />𝐚𝐩𝐭-𝐠𝐞𝐭 - Package handling utility for Debian-based distributions. 📦<br />𝐲𝐮𝐦 - Package manager for RPM-based distributions. 🍲<br />𝐭𝐚𝐫 - Archive files. 🗃️<br />𝐳𝐢𝐩 - Package and compress (archive) files. 📦<br />𝐮𝐧𝐳𝐢𝐩 - Extract compressed files. 📂<br />𝐰𝐠𝐞𝐭 - Retrieve files from the web. 🌐<br />𝐜𝐮𝐫𝐥 - Transfer data from or to a server. 🔄<br />𝐬𝐬𝐡 - OpenSSH client (remote login program). 🚪<br />𝐬𝐜𝐩 - Secure copy (remote file copy program). 🔒<br />𝐫𝐬𝐲𝐧𝐜 - Remote file and directory synchronization. 🔄<br />𝐡𝐨𝐬𝐭𝐧𝐚𝐦𝐞 - Show or set the system's host name. 🏠<br />𝐩𝐢𝐧𝐠 - Send ICMP ECHO_REQUEST to network hosts. 📶<br />𝐧𝐞𝐭𝐬𝐭𝐚𝐭 - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. 🌐<br />𝐢𝐟𝐜𝐨𝐧𝐟𝐢𝐠 - Configure a network interface. 🌐<br />𝐢𝐩 - Show/manipulate routing, devices, policy routing, and tunnels. 🌐<br />𝐢𝐩𝐭𝐚𝐛𝐥𝐞𝐬 - Administration tool for IPv4 packet filtering and NAT. 🛡️<br />𝐬𝐲𝐬𝐭𝐞𝐦𝐜𝐭𝐥 - Control the systemd system and service manager. 🔄<br />𝐣𝐨𝐮𝐫𝐧𝐚𝐥𝐜𝐭𝐥 - Query and display messages from the journal. 📜<br />𝐜𝐫𝐨𝐧𝐭𝐚𝐛 - Schedule periodic background jobs. ⏰<br />𝐬𝐮𝐝𝐨 𝐬𝐮 - Allows us to switch to a different user and execute one or more commands in the shell without logging out from our current session. 🛡️<br />𝐦𝐨𝐮𝐧𝐭 - Mount a file system. 📂<br />𝐮𝐦𝐨𝐮𝐧𝐭 - Unmount a file system. 📂</p>
<p>🐧 Use these commands to interact with your Linux system and perform various administrative tasks! 🚀</p>
]]></content:encoded></item><item><title><![CDATA[Installing MySQL on Ubuntu: A Beginner’s Guide]]></title><description><![CDATA[MySQL is one of the most popular open-source relational database management systems in the world. Whether you’re setting up a web application, managing data for a project, or simply learning about databases, installing MySQL on your Ubuntu system is ...]]></description><link>https://blog.shazeedul.dev/installing-mysql-on-ubuntu-a-beginners-guide</link><guid isPermaLink="true">https://blog.shazeedul.dev/installing-mysql-on-ubuntu-a-beginners-guide</guid><category><![CDATA[Databases]]></category><category><![CDATA[MySQL]]></category><category><![CDATA[Ubuntu]]></category><dc:creator><![CDATA[Syed Shazeedul Islam]]></dc:creator><pubDate>Wed, 10 Jul 2024 05:04:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/Y9kOsyoWyaU/upload/27ca970b9f0cd9e06973a5f13d25f383.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>MySQL is one of the most popular open-source relational database management systems in the world. Whether you’re setting up a web application, managing data for a project, or simply learning about databases, installing MySQL on your Ubuntu system is a crucial skill. In this step-by-step guide, we will walk you through the process of installing MySQL on an Ubuntu machine.</p>
<h2 id="heading-step-1-update-your-package-repository"><strong>Step 1: Update Your Package Repository</strong></h2>
<p>Before installing any software on Ubuntu, it’s essential to update the package repository to ensure you have the latest information about available packages. Open your terminal and run the following commands:</p>
<pre><code class="lang-bash">sudo apt update
</code></pre>
<p>The <code>sudo apt update</code> command is used to refresh the package information on a Debian-based Linux system. It ensures that your system’s package manager (APT, which stands for Advanced Package Tool) has the latest information about available packages and their versions from the configured software repositories.</p>
<p>Then Upgrade:</p>
<pre><code class="lang-bash">sudo apt upgrade
</code></pre>
<p>The <code>sudo apt upgrade</code> command is used to upgrade the installed packages on a Debian-based Linux system, such as Ubuntu. This command will search for updates to your installed packages and, if any updates are available, it will prompt you to confirm the upgrade. It is a good practice to regularly run this command to keep your system up to date with the latest software updates and security patches.</p>
<h2 id="heading-step-2-install-mysql"><strong>Step 2: Install MySQL</strong></h2>
<p>Now, let’s install MySQL by using the following command:</p>
<pre><code class="lang-bash">sudo apt install mysql-server
</code></pre>
<p>This command will prompt you to confirm the installation by typing “Y” and then hitting Enter. The MySQL server package and dependencies will be downloaded and installed.</p>
<h2 id="heading-step-3-secure-your-mysql-installation"><strong>Step 3: Secure Your MySQL Installation</strong></h2>
<p>After MySQL is installed, it’s important to secure it to prevent unauthorized access and enhance security. The following command will initiate the MySQL secure installation process:</p>
<pre><code class="lang-bash">sudo mysql_secure_installation
</code></pre>
<p>You will be asked a series of questions to configure security settings. It’s advisable to answer “Y” (yes) to most of the questions, but you can customize this to suit your requirements.</p>
<ol>
<li><strong>Question:</strong> Type your password and press <code>Y</code> to set up the <code>VALIDATE PASSWORD</code> component which checks whether the new password is strong enough. If you don’t want to <code>VALIDATE PASSWORD</code> Then press <code>N</code>to set (No).</li>
</ol>
<ol>
<li><ol>
<li>If you press yes then follow those steps:  Enter <code>0</code>, <code>1</code>, or <code>2</code> depending on the password strength you want to set :</li>
</ol>
</li>
</ol>
<ul>
<li><ol>
<li><ul>
<li><p><code>0</code> – Low. The password consists of at least 8 characters.</p>
<ul>
<li><p><code>1</code> – Medium. The password consists of at least 8 characters (including numeric, mixed case, and special characters).</p>
</li>
<li><p><code>2</code> – Strong. The password consists of at least 8 characters (including numeric, mixed case, and special characters, and compares the password to a dictionary file).</p>
</li>
</ul>
</li>
<li><p>Please set the password for root and enter the password you want to set.</p>
</li>
<li><p>Once you specify the required strength, enter and re-enter the password.</p>
</li>
<li><p>The program evaluates the strength of your password and requires confirmation <code>Y</code> to continue.</p>
</li>
</ul>
</li>
</ol>
</li>
</ul>
<ol start="2">
<li><strong>Question:</strong> Remove anonymous users.</li>
</ol>
<p><strong>Answer:</strong> To remove the demo/test user, press <code>Y</code>. If you want to keep them, press <code>N</code> to set it to ‘No’.</p>
<ol start="3">
<li><strong>Question:</strong> Disallow root login remotely?</li>
</ol>
<p><strong>Answer:</strong> Press <code>Y</code> to disable remote access to the MySQL server. If you want to enable remote access, press <code>N</code>.</p>
<ol start="4">
<li><strong>Question:</strong> Remove the test database and access to it.</li>
</ol>
<p><strong>Answer:</strong> <code>Y</code> to remove the test database and access to it or <code>N</code> for allow. This is a recommended security measure to remove the default test database, which is often unnecessary and can be a potential security risk if left in place. Removing it helps to enhance the security of your MySQL installation.</p>
<ol start="5">
<li><strong>Question:</strong> Reload privilege tables?</li>
</ol>
<p><strong>Answer:</strong> <code>Y</code> for “Yes.” and <code>N</code> for “No”. Reloading the privilege tables is essential after making changes to the MySQL user accounts and permissions. This ensures that the changes take effect immediately and that MySQL enforces the updated user privileges. It’s necessary to properly secure and configure MySQL as per your settings during the installation process.</p>
<p>Your MySQL installation is now secure.</p>
<h2 id="heading-step-4-start-and-enable-mysql"><strong>Step 4: Start and Enable MySQL</strong></h2>
<p>MySQL may not start automatically after installation. To ensure MySQL starts with your system, you can use the following commands:</p>
<pre><code class="lang-bash">sudo systemctl start mysql
</code></pre>
<pre><code class="lang-bash">sudo systemctl <span class="hljs-built_in">enable</span> mysql
</code></pre>
<p>Now, MySQL will start automatically every time your system boots.</p>
<h2 id="heading-step-5-check-mysql-status"><strong>Step 5: Check MySQL Status</strong></h2>
<p>You can check if MySQL is running properly with the following command:</p>
<pre><code class="lang-bash">sudo systemctl status mysql
</code></pre>
<p>You should see a status message indicating that MySQL is active and running.</p>
<h2 id="heading-step-6-test-your-mysql-installation"><strong>Step 6: Test Your MySQL Installation</strong></h2>
<p>To verify that MySQL is functioning correctly, you can log in as the root user:</p>
<pre><code class="lang-bash">mysql -u root -p
</code></pre>
<p>You’ll be prompted to enter the root password you set during the secure installation. If you can log in without any issues, your MySQL installation is successful.</p>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>Congratulations! You have successfully installed MySQL on your Ubuntu system. MySQL is a powerful and versatile database management system that can be used for various applications, from web development to data analysis. You can now start creating databases, and tables, and managing your data with MySQL on your Ubuntu machine.</p>
<p><strong>Happy Coding 😉</strong></p>
]]></content:encoded></item></channel></rss>