โค้ดดิ้ง

วิธีการ Deploy Laravel กับ Hostinger

ขั้นตอนที่ 1 – การเตรียมการ

ก่อนที่จะเริ่มต้น เราจะต้อง เปิดใช้งานแผนโฮสติ้ง และ เพิ่มโดเมน ที่เราต้องการใช้งาน

ขั้นตอนที่ 2 – อัปโหลดและย้ายไฟล์

อัปโหลดไฟล์เว็บไซต์ Laravel ไปยังไฟล์ของเว็บไซต์ ซึ่งอยู่ระดับเดียวกันกับโฟลเดอร์ public_html หากโปรเจ็กต์ของเราชื่อ laravel โครงสร้างไฟล์จะมีลักษณะดังนี้ :

หลังจากนั้น ให้เปิด โฟลเดอร์ laravel/public/และย้ายไฟล์ทั้งหมดไปที่ public_html :

หลังจากย้าย โครงสร้างไฟล์ของ public_html ควรมีลักษณะดังนี้:

ขั้นตอนที่ 3 – แก้ไขไฟล์ index.php และ .htaccess

เปิด ไฟล์ index.phpบน File Manager และแทนที่เนื้อหาดังต่อไปนี้ สิ่งนี้จะทำให้ Laravel เข้าใจโครงสร้างไฟล์ใหม่:

<?php
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/../laravel/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);

จากนั้น เปิด ไฟล์ .htaccess และเพิ่มกฎต่อไปนี้เพื่อให้ Laravel โหลดเนื้อหาได้อย่างถูกต้อง:

<IfModule mod_rewrite.c> 
  RewriteEngine บน
  RewriteRule ^(.*)$ public/$1 [L] 
</IfModule>

Nidkoma

ชื่นชอบในการเขียนบทความ และการหาความรู้ในด้านต่างๆ ชอบถ่ายรูป ถ่ายวิดีโอ ชอบฟัง แต่ไม่ชอบพูดมั้ง ?? ^ ^
Back to top button