LoginSignup
2
0

More than 3 years have passed since last update.

Google App EngineにLaravelをデプロイしようとしてハマったのでメモ

Last updated at Posted at 2020-09-20

環境

PHP 7.3
Laravel 7.4
React 16.10

設定ファイル

gcloud app deploy 時に利用する設定ファイルです。
一部省略してます。また、余計な物が入ってるかもしれません。

app.yaml

env: standard
instance_class: F1

env_variables:
    APP_NAME: Laravel Project
    APP_ENV: *
    APP_KEY: *
    APP_DEBUG: true
    APP_STORAGE: /tmp
    VIEW_COMPILED_PATH: /tmp

    LOG_CHANNEL: stackdriver // googleのstackdriverを使うため

    BROADCAST_DRIVER: log
    CACHE_DRIVER: file
    QUEUE_CONNECTION: sync
    SESSION_DRIVER: cookie //stackdriver時にはcookieにする必要あり
    SESSION_LIFETIME: 120


handlers:
    # Serve images as static resources.
    - url: /css
      static_dir: public/css
    - url: /js
      static_dir: public/js
    - url: /fonts
      static_dir: public/fonts
    - url: /images/(.*)
      static_files: public/images/\1
      upload: .+\.(gif|png|jpg)$

    # Serve your app through a front controller at index.php or public/index.php.
    - url: .*
      script: auto

automatic_scaling:
    min_idle_instances: 1
    max_idle_instances: 1
    max_pending_latency: 2000ms

エラー別対応

There is no existing directory at "/var/www/storage/logs" and its not buildable: Read-only file system

未確認ですが、GAE環境のこのディレクトリはRead only環境となっているのではと推測しました。今回は次の設定で利用先のディレクトリを変更して回避しました。


APP_STORAGE: /tmp

Class 'Facade\Ignition\IgnitionServiceProvider' not found

依存関係の問題です。
dev環境とprod環境で設定を変えている場合は、composerで依存関係を修正して下さい。
基本的には、dev環境とprod環境の両方でファイルを使えるように設定すればOKです。
また、依存関係を変更した後はcasheを削除してから再実行するようにしてください。(これではまってました)

詳細は下記のURLをご覧ください。
stackoverflow laravelをGAEにデプロイした時のエラー

Uncaught SyntaxError: Unexpected token <

ビルドしたフロントのファイル(app.js)が読み込めなかったために起きた事象です。
app.yamlのhandlerを適切に設定していれば回避できました。

handlers:
    # Serve images as static resources.
    - url: /css    // <- ここで読み込むファイルの種類を設定
      static_dir: public/css   // <- 実際の置き場所を指定
    - url: /js
      static_dir: public/js
    - url: /fonts
      static_dir: public/fonts
    - url: /images/(.*)
      static_files: public/images/\1
      upload: .+\.(gif|png|jpg)$

正直細かいところが分からなかったので詳細は公式リファレンスをご参照ください。
GCPリファレンス GAEのapp.yamlの設定 PHP7

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