blogですかい

仕事、プライベートで学んだことなどを発信し、その内容がたとえ少数でも誰かの役に立ったらなら、それはとっても嬉しいなって

Google Compute Engine でLAMP環境作ってみた #PHPで何か作ろうかい

事前準備

  • https://cloud.google.com/ にSign in
  • Cloud ConsoleにてProjectを作成
  • Billing Settingにてクレジットカードの登録

インスタンスを立てる

  1. Compute Engineのメニューにて、「NEW INSTANCE」ボタンをクリック
  2. 下記のように、フォームに必要な情報を入力して、「Create」ボタンをクリック

f:id:oh-sky:20130518171018p:plain

Machine Typeのデフォルトが「n1-standard-1」になっているので注意

sshインスタンスに接続する

  1. ローカルマシンにgcutilをインストール
  2. Instance Detailの「Equivalent REST or ssh」の「ssh」をクリックすると実行するべきコマンドが出てくるので実行する。出力されるURLにブラウザでアクセスし、返ってくるコードをコマンドラインに入力する。
$ ./gcutil --service_version="******" --project="******" ssh  --zone="us-central1-a" "kanaka"
Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute.readonly+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.read_only+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.read_write+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.write_only+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=*********************.apps.googleusercontent.com&access_type=offline

Enter verification code: ****************************************************
Authentication successful.
WARNING: You don't have an ssh key for Google Compute Engine. Creating one now...
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
INFO: Updated project with new ssh key. It can take several minutes for the instance to pick up the key.
INFO: Waiting 300 seconds before attempting to connect.
INFO: Running command line: ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no -i /Users/Yoshihiro/.ssh/google_compute_engine -A -p 22 Yoshihiro@***.***.***.*** --
Warning: Permanently added '***.***.***.***' (RSA) to the list of known hosts.
Linux kanaka 3.3.8-gcg-201304231037 #7 SMP Tue Apr 23 10:38:59 PDT 2013 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Yoshihiro@kanaka:~$ 

初回は少々時間がかかるが、2回目以降はすぐに繋がる。

とりあえずバージョンの確認をしてみる

Yoshihiro@kanaka:~$ uname -a
Linux kanaka 3.3.8-gcg-201304231037 #7 SMP Tue Apr 23 10:38:59 PDT 2013 x86_64 GNU/Linux
Yoshihiro@kanaka:~$ cat /etc/debian_version 
7.0

wheezyはkernel 3.2が標準なので、独自ビルドのようです

LAMP環境にする

Apache2 MySQL5.5 PHP5 のインストール

Yoshihiro@kanaka:~$ sudo aptitude update
Yoshihiro@kanaka:~$ sudo aptitude upgrade
Yoshihiro@kanaka:~$ sudo aptitude install apache2 php5 mysql-server

ファイアウォールの設定

  1. Networksのdetailにて、Firewallsの「Create new」をクリック

f:id:oh-sky:20130518180332p:plain

  1. HTTPを通す設定を作成

f:id:oh-sky:20130518180357p:plain

  1. ブラウザでWebアクセスができるようになります。

f:id:oh-sky:20130518180622p:plain