ハマログ

株式会社イーツー・インフォの社員ブログ

AppEngineでphpMyAdminを動かす

データベースにMySQLを利用することが多いのですが、GCPで環境を作るときにGCEで環境を構築しました。

が、よく考えたらGCPにはApp Engineがあるなーと思って調べたらそちらのほうが適していそうなので、App Engineで作り直しました。

手順

コンソールからCloud Shellをアクティブにします
phpMyAdminのソースコードをダウンロードします。今回はPHP7.4の環境を利用するので、phpMyAdmin 5.1.1を取得しました。

ホームディレクトリで作業しましたがどこでも大丈夫です。
cd /home/kaneko
ファイル取得
wget https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-all-languages.zip
展開
unzip https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-all-languages.zip
App Engineの定義ファイルを作ります
mkdir phpMyAdmin
cd phpMyAdmin
touch app.yaml
内容
service: default
runtime: php74

handlers:

  - url: /(.+\.(ico|jpg|png|gif))$
    static_files: \1
    upload: (.+\.(ico|jpg|png|gif))$

  - url: /(.+\.(htm|html|css|js))$
    static_files: \1
    upload: (.+\.(htm|html|css|js))$

  - url: /(.+\.php)$
    script: \1
    login: admin

  - url: /.*
    script: index.php
    login: admin
phpMyAdminの設定ファイルを作ります
touch config.inc.php
<?php
$cfg['blowfish_secret'] = '<シークレットキー>' /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

/*
 * Servers configuration
 */
$i = 0;

// Change this to use the project and instance that you've created.
$host = '/cloudsql/<Cloud SQLの接続文字列>';
$type = 'socket';

/*
* First server
*/
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['socket'] = $host;
$cfg['Servers'][$i]['connect_type'] = $type;
$cfg['Servers'][$i]['compress'] = false;
/* Select mysql if your server does not have mysqli */
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
/*
 * End of servers configuration
 */

/*
 * Directories for saving/loading files from server
 */
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';

/*
* Other settings
*/
$cfg['PmaNoRelation_DisableWarning'] = true;
$cfg['ExecTimeLimit'] = 60;
$cfg['CheckConfigurationPermissions'] = false;
php.iniの設定
標準で無効になっている関数を有効化します
touch php.ini
<?php
google_app_engine.enable_functions = "php_uname, getmypid"						

デプロイ

デプロイ前に接続制限をかけます。コンソールから作業します。App Engine→ファイアウォールルール→ルールを作成

デフォルトを拒否に変更して、許可するIPを追加します。
デプロイします。Cloud Shellを操作するユーザーに以下の権限が必要です。IAMから設定します。
新しいバージョンをデプロイするには、App Engine デフォルト サービス アカウントに対するサービス アカウント ユーザー(roles/iam.serviceAccountUser)ロール、プロジェクトに対する Cloud Build 編集者(roles/cloudbuild.builds.editor)ロールと Cloud Storage オブジェクト管理者(roles/storage.objectAdmin)ロールも必要です。
https://cloud.google.com/appengine/docs/standard/php7/roles?hl=jaより
gcloud app deploy

Please choose the region where you want your App Engine application located:

 [1] asia-east1    (supports standard and flexible)
 [2] asia-east2    (supports standard and flexible and search_api)
 [3] asia-northeast1 (supports standard and flexible and search_api)
 [4] asia-northeast2 (supports standard and flexible and search_api)
 [5] asia-northeast3 (supports standard and flexible and search_api)
 [6] asia-south1   (supports standard and flexible and search_api)
 [7] asia-southeast1 (supports standard and flexible)
 [8] asia-southeast2 (supports standard and flexible and search_api)
 [9] australia-southeast1 (supports standard and flexible and search_api)
 [10] europe-central2 (supports standard and flexible)
 [11] europe-west   (supports standard and flexible and search_api)
 [12] europe-west2  (supports standard and flexible and search_api)
 [13] europe-west3  (supports standard and flexible and search_api)
 [14] europe-west6  (supports standard and flexible and search_api)
 [15] northamerica-northeast1 (supports standard and flexible and search_api)
 [16] southamerica-east1 (supports standard and flexible and search_api)
 [17] us-central    (supports standard and flexible and search_api)
 [18] us-east1      (supports standard and flexible and search_api)
 [19] us-east4      (supports standard and flexible and search_api)
 [20] us-west1      (supports standard and flexible)
 [21] us-west2      (supports standard and flexible and search_api)
 [22] us-west3      (supports standard and flexible and search_api)
 [23] us-west4      (supports standard and flexible and search_api)
 [24] cancel
Please enter your numeric choice:  3

(略)

Do you want to continue (Y/n)?  y

Created .gcloudignore file. See `gcloud topic gcloudignore` for details.
Uploading 1809 files to Google Cloud Storage
5%
10%
15%
service: phpmyadmin
20%
25%
30%
35%
40%
45%
50%
55%
60%
65%
70%
75%
80%
86%
91%
96%
100%
100%
File upload done.
Updating service [default]...done.     
Setting traffic split for service [default]...done.     
成功
みえました
Cloud SQLGCPmysqlPHPphpMyAdminPMAsql

  kaneko tomo   2022年1月9日


関連記事

AWS WAFのカスタムレスポンスを試してみる

AWS WAFで、カスタムレスポンスを返すことができるようになったので試してみま…

AWSとは何ぞや

皆様お疲れ様です。 今まで経験した環境では特にAWSと関わることがなく 存在は知…

AWS EC2でファイル共有 東京はまだだけど米国サーバーでEFS試してみる

こんにちはいけしまです。前回のブログ更新から5ヶ月もたってしまいました。すみませ…


← 前の投稿

次の投稿 →