Root and Subdirectory Deployment

We are going to discuss basic changes in our template before deploying our template in the root domain.

TIP

Firstly, you have to follow all the installation steps if you have not done it before. You can find these steps here.
Step 1

First, run the npm run mix --production or yarn mix --production command to generate the build.

Step 2

You have to place all public files inside your server's public_html folder and your Laravel is in a separate folder.

For example:-

We have two folder in our server.

        
        public_html/ -> (folder for public accessible)
        ├── css/
        ├── fonts/
        ├── images/
        ├── js/
        ├── .htaccess
        ├── favicon.ico
        ├── index.php
        ├── mix-manifest.json
        ├── web.config
        └── robots.txt

        laravel/ -> (folder where laravel live)
        ├── app/
        ├── bootstrap/
        ├── config/
        ├── database/
        ├── frontend/
        ├── resources/
        ├── routes/
        ├── storage/
        ├── tests/
        ├── vendor/
        ├── .babelrc
        ├── .env
        ├── .gitattributes
        ├── .gitignore
        ├── .styleci.yml
        ├── artisan
        ├── composer.json
        ├── docker-compose.yml
        ├── package.json
        ├── phpunit.xml
        ├── server.php
        └── webpack.mix.js
        
    

As an above structure, we have to changes some paths in the index.php file in the public or public_html file. Also, we have to bind the document root to he current file path, where index.php exists.

      
<?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Check If Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is maintenance / demo mode via the "down" command we
| will require this file so that any prerendered template can be shown
| instead of starting the framework, which could cause an exception.
|
*/

if (file_exists(__DIR__.'/../laravel/storage/framework/maintenance.php')) {
    require __DIR__.'/../laravel/storage/framework/maintenance.php';
}

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/

require __DIR__.'/../laravel/vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/

$app = require_once __DIR__.'/../laravel/bootstrap/app.php';

$app->bind('path.public', function() {
    return base_path('/../public_html');
});

$kernel = $app->make(Kernel::class);

$response = tap($kernel->handle(
    $request = Request::capture()
))->send();

$kernel->terminate($request, $response);
      
    

Subdirectory deployment

For your Subdirectory deployment, you have to make path changes as per your Subdirectory folder structure in the above file.

Note: public_html folder may differ from server to server.

Congratulation! You successfully deployed your project.