LoginSignup
1
2

More than 5 years have passed since last update.

初めてのGCP(google cloud platform) part2 (php+smarty環境)

Last updated at Posted at 2019-01-07

1から、GCPにphp+smarty環境を構築してみました。
結構はまったので、メモ的な備忘録。

◆一番はまったところ
smartyのコンパイルファイル生成する方法にはまった。
下記2点を設定する必要があった。
・php.iniで、バケット指定
・index.phpでgsバケット/フォルダ指定が必要

◆準備
・gae必要ファイル
app.yaml   (index.php指定)
php.ini    (※追加ファイル)
index.php
/templates/
  ┗index.tpl
/smarty/   (※追加プラグイン)
  ┗(公式SmartyからDLしたファイル中、/libs/の中身をUPロードする)
    ※libs中身がsmarty本体

・ストレージのバケット作成
  ①gcp左上メニューから→ストレージ→ブラウザ→バケット作成
   例)バケット:test1作成 (Regional / ASIA-NORTHEAST1)
  ②バケットにフォルダ作成 (smartyコンパイル・キャッシュファイル用)
    ┣/compiled/ (フォルダ)
    ┗/cache/ (フォルダ)

 ※バケット権限設定を閲覧者:読み込み→書き込みに変更している
  →必要かは調査しきれてない・・(ファイル生成するので必要とおもう・・多分)

◆手順の流れ
①app.yamlがある同じ場所にphp.iniファイルを作成

・app.yaml

runtime: php55
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: index.php

・php.ini

allow_url_include = "1"
google_app_engine.allow_include_gs_buckets = "バケット名(のみ)"

(※バケット名→gcpメニュー:ストレージ/ブラウザで、バケット作成したバケット名)
例)google_app_engine.allow_include_gs_buckets = "test1"

②app.yamlで指定してるindex.php

・index.php

<?php
// Smartyクラス読込
require_once("smarty/Smarty.class.php");

// Smartyインスタンス生成
$smarty = new Smarty();

// テンプレートディレクトリ
$smarty->template_dir = "./templates/";

// コンパイルディレクトリ
$smarty->compile_dir= "gs://バケット名/compiled/";
$smarty->cache_dir="gs://バケット名/cache/";
$smarty->display('index.tpl');

例)
$smarty->compile_dir= "gs://test1/compiled/";
$smarty->cache_dir="gs://test1/cache/";

・index.tpl

<!DOCTYPE html>
<html>
<head>
     <meta charset="utf-8">
     <title>初めてのGCP php+Smarty環境</title>
</head>
<body>
    表示テスト
</body>
</html>
<script>
  {literal}
    alert("表示OK");
  {/literal}
</script>

③デプロイして確認。

gcloud app deploy ※デプロイ
gcloud app browse ※url表示

url飛んで、アラート「表示OK」でたら成功。

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