10
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

laravelをGAE SE php7.2環境で動かす

実行環境

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.2
BuildVersion:   18C54
$ docker -v
Docker version 18.09.0, build 4d60db4
$ docker-compose -v
docker-compose version 1.23.2, build 1110ad01
$ gcloud -v
Google Cloud SDK 228.0.0
bq 2.0.39
core 2018.12.07
gsutil 4.34

laravel5.7のアプリケーションを作成

php7.2のコンテナを用意

Dockerfile
FROM php:7.2.3-fpm
ENV COMPOSER_ALLOW_SUPERUSER 1

RUN mkdir /app
WORKDIR /app

RUN apt-get update && apt-get install -y git libmcrypt-dev zlib1g-dev libpq-dev zip unzip && \
    apt-get clean

RUN curl -sS https://getcomposer.org/installer | php && \
    mv ./composer.phar /usr/local/bin/composer

RUN composer global config repositories.packagist composer https://packagist.jp && \
    composer global require hirak/prestissimo

EXPOSE 9000
docker-compose.yml
version: '3'

services:
  php:
    build: .
    command: php artisan serve --host=0.0.0.0 --port=8000
    volumes:
      - .:/app:cached
    ports:
      - "8000:8000"
$ docker-compose build

アプリケーション作成

$ docker-compose run --rm php composer create-project --prefer-dist laravel/laravel application "5.7.*"

アプリケーションをルートディレクトリに移動

$ mv ./application/* ./application/.[^\.]* ./
$ rm -rf ./application

実行

$ docker-compose up

GAEにデプロイ

app.yaml

app.yaml
runtime: php72

env_variables:
  APP_LOG: errorlog
  APP_KEY: MY_APP_KEY
  APP_STORAGE: /tmp

APP_KEY作成

$ sed -i '' "s#MY_APP_KEY#$(docker-compose run --rm php php artisan key:generate --show --no-ansi)#" app.yaml

.envをGAEのデプロイ対象から除外

.gcloudignore
.env

APP_STORAGEで指定した/tmpにキャッシュを書き込むためのコード変更

/config/view.php
/*
'compiled' => env(
    'VIEW_COMPILED_PATH',
    realpath(storage_path('framework/views'))
),
*/
// 追加
'compiled' => storage_path(),
/bootstrap/app.php
// 追加
$app->useStoragePath(env('APP_STORAGE', base_path() . '/storage'));

/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/

return $app;

プロジェクトID設定

$ gcloud projects list
$ gcloud config set project <PROJECT_ID>

設定確認

$ gcloud config list

デプロイ

$ gcloud app deploy

デプロイされたことを確認

$ gcloud app browse

Register as a new user and use Qiita more conveniently

  1. You can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
10
Help us understand the problem. What are the problem?