deploy laravel 4 app in a subdomain

后端 未结 3 1323
我在风中等你
我在风中等你 2021-01-14 07:46

I\'m about to deploy laravel 4 on a shared web host into a subdomain and I\'m a bit confused about what to do. I got it working on a hostpapa account but wasnt happy with th

3条回答
  •  生来不讨喜
    2021-01-14 08:42

    This is super easy on shared hosting.

    Step 1: Understanding your folder structure. The layout of your shared hosting should generally look something like this:

    /
     username
       home
         public_html
         subdomain-name
         laravel-files (optional)
         ...other folders etc
    

    As you hopefully know, all your public files for your site will be in your public_html folder.

    Note: sometimes a subdomain will be inside the public_html folder. That is okay but I recommend creating your subdomain folder above the root for a little bit of extra security. You can do that easily in cPanel but changing the path to the subdomain when you are creating it.

    Step 2: Upload your Laravel files above the root (above public_html) or in a subfolder if you want it to be cleaner.

    For a small project I generally upload the files into the "home" folder above. But for cleaner structure you may want to create a folder inside that "home" folder called "laravel-files".

    What follows is how to do it in an "laravel-files" folder. If you upload them to "home" instead then all you need to do is get rid of all references to "/laravel-files" below.

    Step 3: edit your public/index.php and your bootstrap/paths.php files:

    In paths.php

    change

    'app' => __DIR__.'/../app',
    

    to:

    'app' => __DIR__.'/../laravel-files/app',
    

    change:

    'public' => __DIR__.'/../public',
    

    to:

    'public' => __DIR__,
    

    change:

    'base' => __DIR__.'/..',
    

    to:

    'base' => __DIR__.'/../laravel-files',
    

    change:

    'storage' => __DIR__.'/../app/storage',
    

    to:

    'storage' => __DIR__.'/../laravel-files/app/storage',
    

    In index.php

    change:

    require __DIR__.'/../bootstrap/autoload.php';
    

    to:

    require __DIR__.'/../laravel-files/bootstrap/autoload.php';
    

    change:

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

    to:

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

    Now what you'll need to do is, as I said upload your laravel project to your "laravel files" folder.

    The only thing you wont upload there is the contents of your laravel "public" folder, which should instead be uploaded to your "subdomain-name" folder (this includes your index.php and all your css js files etc).

    Hope this helps!

    Please note my answer is based on this question: How to install Laravel 4 to a web host subfolder without publicly exposing /app/ folder? but tailored for your situation.

提交回复
热议问题