LoginSignup
2
1

More than 1 year has passed since last update.

Azure App ServiceでLaravelアプリのDocument rootでハマった件

Last updated at Posted at 2020-04-03

※2022.3.8 追記

最近のバージョンだと変更があったようで、コメントを頂きました(@rana_kualuさんありがとうございますmm)
https://qiita.com/hisw/items/69a3529de7f9242e3f75#comment-0b3f657f0c8989b71dd9

背景

Azureを練習しようとGithubに上げている簡単なLaravelアプリをデプロイしようと試みる。
とりあえずApp ServiceでPHPの環境を作成し、デプロイセンターからGithubよりデプロイ。

問題発生

標準でDocument rootが/home/site/wwwrootになっているため、ソースをデプロイしてもうまくアクセスできず。(/home/site/wwwroot/publicを見てほしい)
Ubuntu環境のApacheで動いていることが分かったため、/etc/apache2/sites-available/にある000-default.confやdefault-ssl.confを見て「$APACHE_DOCUMENT_ROOT」を変えてみようとAzureのコンソール画面から『設定>構成>アプリケーション設定』で環境変数を設定してみるも、これも効かず。(SSHで入って環境変数↑をechoしてみると変更はちゃんと効いていたのに...)

解決した方法

正攻法か分かりませんが、Laravelアプリのソースに「.htaccess」置いて回避しました。
Nginx+php-fpmの方に慣れていたのでこの方法に行きつくまでかなりかかりました...。

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteRule ^.*$ /public/$1 [NC,L,QSA]
2
1
2

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
2
1