2018年6月29日 星期五

[GCP]安裝phpmyadmin踩雷筆記


1.打開好物Google cloud shell
2.重要觀念,一個project -> 一個SQL instance ->一個phpmyadmin
3.新建project
4.新建SQL的instance
5.在好物shell中,把phpmyadmin的檔案clone回來
wget https://files.phpmyadmin.net/phpMyAdmin/4.6.3/phpMyAdmin-4.6.3-all-languages.tar.bz2

6.新增一個資料夾放phpmyadmin
mkdir phpMyAdmin

7.解壓縮剛剛clone回來的檔案,並放到剛剛加的資料夾中
tar -xvf phpMyAdmin-4.6.3-all-languages.tar.bz2 -C phpMyAdmin --strip-components=1

8.新增部屬用檔案app.yaml
cd phpMyAdmin  //到剛剛新增的資料夾
vim app.yaml  //新增一個檔案叫app.yaml

9.增加以下內容
(註:vim的基本用法「i」是進入編輯模式,「esc」是進入指令模式,
指令「:q!」是不存檔離開,指令指令「:wq」是存檔離開)
service: phpmyadmin
runtime: php55
api_version: 1

handlers:

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

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

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

- url: /.*
  script: index.php
  login: admin

10.設定phpmyadmin,增加檔案config.inc.php
vim config.inc.php

11.放入以下內容
<!-- [START all] -->
<?php
// [START_EXCLUDE silent]
/**
 * Copyright 2016 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// [END_EXCLUDE]
/*
 * This is needed for cookie based authentication to encrypt password in
 * cookie
 * http://www.question-defense.com/tools/phpmyadmin-blowfish-secret-generator
 */
$cfg['blowfish_secret'] = '{{your_secret}}'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
 //去此網址產生一個碼:https://www.question-defense.com/tools/phpmyadmin-blowfish-secret-generator
/*
 * Servers configuration
 */
$i = 0;

// Change this to use the project and instance that you've created.
$host = '/cloudsql/{{your_connection_string}}'; //要換成你的connectName,可以在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;
// [END all]

12.編輯php基本設定
vim php.ini

13.放入以下內容
google_app_engine.enable_functions = "php_uname, getmypid"
14.開始部屬囉
gcloud components update //測試是否套件為最新
gcloud app deploy //進行部屬啦

15.部屬完後進入網址

https://phpmyadmin-dot-[YOUR_APP_ID].appspot.com //[YOUR_APP_ID]可以從header選擇專案的跳窗中找到
//其實gcloud app deploy以後出現的target url,也可以參考

16.結果竟然出現
404. That’s an error.

The requested URL was not found on this server. That’s all we know.

17.猜想是權限問題,進入API頁面,搜尋SQL,並點擊進去Google Cloud SQL API,進行啟用
18.再glcoud app deploy一次,並先複製target url,等一下可以用
19.部屬完後,貼上剛剛的網址,就順利進去啦!
20.帳號是root,密碼是你剛剛設定SQL時設定的
21.竟然還是出錯
 mysqli_real_connect(): MySQL server has gone away
 mysqli_real_connect(): Error while reading greeting packet. PID=-1
 mysqli_real_connect(): (HY000/2006): MySQL server has gone away

22.後來我放著隔天在次登入後,就可以進去了,我猜是SQL還未準備好吧

沒有留言:

張貼留言