LoginSignup
0
1

More than 5 years have passed since last update.

LumenをGoogleAppEngineで動かしたメモ

Posted at

GoogleAppEngineでPHP

デプロイ後の公開URL http://kaihatsu-laravel5.appspot.com

GAE で必要なもの準備

memcached は使わないようにしなければならないっぽい。なぜかはよくわからないけど。

> brew uninstall php55-memcached php55-memcache

DB やログは、GAEでも開発用のGAEでもローカルファイルには書き込めないようにパーミッションがかけられているので、MySQL/PgSQL などといった、外部と通信するソフトを使う必要がある。

起動コマンド

開発サーバを立ち上げるコマンド。

> dev_appserver.py --php_executable_path=/opt/php5/bin/php .

ただし、上手く動いていないっぽい。GoogleAppLauncherからやるのがいい。

Lumen のプロジェクトを作成

> composer.phar create-project laravel/lumen --prefer-dist

GaeSupportLumen をインストール

php artisan gae:setup --config kaihatsu-laravel5

https://github.com/shpasser/GaeSupportL5 からLumen向けにされた https://github.com/shpasser/GaeSupportLumen を利用。

少し工夫:Monologのログ保存の指定で開発時はローカルファイルを指定されているが、GoogleAppLauncher から起動している場合(dev_appserver.py 経由はよくわからない)はログファイルに保存できないといったメッセージが出て実行できない不具合があるので、MonologをSyslogに変えてやる必要がある。なお、GAEサーバで動いている時はSyslogになる。

app/Foundation/Application.php
<?php
/**
 * Created by PhpStorm.
 * User: atys
 * Date: 15/06/16
 * Time: 18:52
 */

namespace App\Foundation;

use Laravel\Lumen\Application as LumenApplication;
use Illuminate\Foundation\ProviderRepository;
use Illuminate\Filesystem\Filesystem;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Shpasser\GaeSupportLumen\Storage\CacheFs;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Monolog\Handler\SyslogHandler;
use Monolog\Logger;

class Application extends \Shpasser\GaeSupportLumen\Foundation\Application
{
    protected function getMonologHandler()
    {
        return new SyslogHandler('intranet', 'user', Logger::DEBUG, false, LOG_PID);
    }
}

そしてLumen で利用するには $app を作り替えた上記のApplicationにしてやる必要があるので、下記のように書き換える。

app/bootstrap/app.php
<?php

require_once __DIR__.'/../vendor/autoload.php';

// Lumenは標準ではDotenvは読まない
 Dotenv::load(__DIR__.'/../');

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/

$app = new App\Foundation\Application(
    realpath(__DIR__.'/../')
);

...

GoogleCloudSQL のセットアップ

GoogleCloudSQL = AmazonRDB みないなもの。

・MySQLドライバーが使えるので、これを使う
・従量制
・地域はアメリカ
・タイプD1の512MB RAM。他にもD2 1GB RAMなどがある。
・希望する場所を「AppEngine アプリ準拠」アプリケーションIDは「kaihatsu-laravel5」
・バックアップを無効(特に意味が無いので)
・アクティベーションポリシーを「オンデマンド」料金をケチるため
・「承認済みの App Engine アプリケーション」に「kaihatsu-laravel5」があるか確認
で作成する。

作成後はGCS にIPv6が割り当てられるので、それを元に設定を作る。

Cloud Storage のセットアップ

Amazon S3 みたいなやつ。

作成したバケット名をメモしておく(今回は「kaihatsu2015-bucket」に設定)

デプロイの準備

設定ファイルの自動生成

> php artisan gae:setup \
--config \
--bucket="<Bucket名>" \
--db-name="<DB名>" \
--db-host="<IPv6>" \
kaihatsu-laravel5

注意:
 デプロイ時はすべてのファイルがアップロードされるので、開発時に作成されたファイルや、設定ファイル「.env」を本番用に上書きしてデプロイする必要がある。

$ appcfg.py -A kaihatsu-laravel5 update appengine                                                                                            git:develop - (m1)

Note: the --oauth2 flag is now the default and can be omitted.

03:37 PM Application: kaihatsu-laravel5; version: 1
03:37 PM Host: appengine.google.com
03:37 PM
Starting update of app: kaihatsu-laravel5, version: 1
03:37 PM Getting current resource limits.
03:37 PM Scanning files on local disk.
03:37 PM Scanned 500 files.
2015-06-15 15:37:45,005 ERROR appcfg.py:1917 Invalid character in filename: vendor/symfony/finder/Symfony/Component/Finder/Tests/Fixtures/r+e.gex[c]a(r)s/dir/bar.dat
03:37 PM Scanned 1000 files.
03:37 PM Scanned 1500 files.
03:37 PM Scanned 2000 files.
03:37 PM Scanned 2500 files.
03:37 PM Scanned 3000 files.
03:37 PM Cloning 3372 application files.
03:37 PM Cloned 2000 files.
03:38 PM Compilation starting.
03:38 PM Compilation completed.
03:38 PM Starting deployment.
03:38 PM Checking if deployment succeeded.
03:38 PM Deployment successful.
03:38 PM Checking if updated app version is serving.
03:38 PM Completed update of app: kaihatsu-laravel5, version: 1

動いたらこんな感じ。

スクリーンショット 2015-06-15 15.42.02.png

日本語ファイル名だめ

~/develop/開発合宿2015 $ appcfg.py -A kaihatsu-laravel5 update appengine-try-php
Note: the --oauth2 flag is now the default and can be omitted.

01:32 PM Host: appengine.google.com
Usage: appcfg.py [options] update <directory> | [file, ...]

appcfg.py: error: Directory '/Users/yasui/Documents/develop/\xe9\x96\x8b\xe7\x99\xba\xe5\x90\x88\xe5\xae\xbf2015' does not contain configuration file appengine-try-php.yaml

プロジェクトディレクトリを指定

~/develop/kaihatsu-gassyuku-2015 $ appcfg.py -A kaihatsu-laravel5 update appengine-try-php 
Note: the --oauth2 flag is now the default and can be omitted.

01:33 PM Host: appengine.google.com
Usage: appcfg.py [options] update <directory> | [file, ...]

appcfg.py: error: Directory '/Users/yasui/Documents/develop/kaihatsu-gassyuku-2015' does not contain configuration file appengine-try-php.yaml

PHP5.4 はダメ

app.yaml で runtime: phpとした時に実行されるのは PHP5.4になるので、runtime: php55としないといけない様子。

~/develop/kaihatsu-gassyuku-2015 $ appcfg.py -A kaihatsu-laravel5 update appengine
Note: the --oauth2 flag is now the default and can be omitted.

01:34 PM Application: kaihatsu-laravel5 (was: helloworld); version: 1
01:34 PM Host: appengine.google.com
01:34 PM
Starting update of app: kaihatsu-laravel5, version: 1
01:34 PM Getting current resource limits.
01:34 PM Scanning files on local disk.
Error 400: --- begin server output ---
PHP 5.4 applications are prevented from being deployed to Google App Engine from any version of the SDK, including older ones. If you need to continue to deploy PHP 5.4 applications for compatibility reasons, you can request that your application be whitelisted for PHP 5.4 deployment by visiting http://goo.gl/qjKEuk.
--- end server output ---

テンプレなど

フルスタックではないので、Laravel5で使える blade の @layout などはない。

試しなので、 https://www.polymer-project.org を使ってみる。

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