1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

非公開ディレクトリを使えないサーバでLaravelを設置する

Posted at

#はじめに
公開フォルダーの上位フォルダーにアクセス権が無い例としては、レンタルサーバーにお名前.comサーバが該当しますが、普通にはLaravelをインストールできないです。
公開フォルダでシステムファイルをさらすことに。

そこで、公開フォルダーにLaravel用にフォルダーを作ってそこに入れてしまいます。

#フォルダー構造

公開フォルダー/
 ├ .htaccess
 ├ index.php
 ├ /system ←ここにLaravelを沈める
 │ ├ .htaccess
 │ ├ /app
 │ ├ /config
 │ ├ /database
 │ ├ /resources
 │ ├ /routes
 │ ├ /storage
 │ └ /vendor
 │  
 └ favicon.ico

##index.phpの中身のパスを編集する
フォルダー構造を変えたので、パスを変更します。

index.php
<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

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__.'/system/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__.'/system/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

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


##systemフォルダーの.htaccessを忘れずに
.htaccessを作成して中身をDeny from allを書いてsystemフォルダーに保存します。

.htaccess

Deny from all

##最後に

できれば、公開フォルダーにシステムを入れる事は避けたいです。
依頼者のサーバを変えれないような場合、
この方法で、設置しておけば、消しちゃ駄目なフォルダーと分かりやすいと思います。
メンテナンス作業やりやすいと思います。

こんな感じで参考になれば。
ありがとうございます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?