LoginSignup
3
3

More than 5 years have passed since last update.

レンタルサーバーでpublicフォルダを見てくれない時の対応

Last updated at Posted at 2016-04-29

Laravelで作ったwebサイトをValue Serverに載せてくれってなった時に
公開フォルダを指定できなかったのでその対策法をメモ。

Value Serverに限らず、レンタルサーバーを借りる場合は稀にあることかと思います。

環境

・Laravel
・Value Server

説明

Value Serverはpublic_html配下にドメインに沿ったフォルダが作られる。

例:

/public_html/example.com/ ←公開フォルダ

この中にLaravelのアプリケーションを入れるとすべて公開されてしまう上に
publicフォルダ内ののindex.phpを一番最初に見てくれない。

そこで、アプリケーションフォルダの中からpublicだけ取り出しフォルダを分ける。

例:

/public_html/laravel ←publicフォルダ以外のlaravel全ソース
--------------/example.com ←publicフォルダの中身

これで実質example.comフォルダがpublicフォルダという構成になるので一件落着。

しかし、このままではうまく動作しません。

最後の一手

publicフォルダ内のindex.phpを以下のように修正。
(bootstrapの前に/laravel/を入れた)

example.com/index.php
require '/../laravel/bootstrap/autoload.php';
...
$app = '/../laravel/bootstrap/app.php';

更に、Laravel定義のpublic_path関数が返す値を変更するために下記を追加。

example.com/index.php
...
$app->bind('path.public', function() {
    return __DIR__;
});

これでちゃんと動くようになると思います。

3
3
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
3
3