それでは、昨日に引き続き、ビギナーの記録的日記を書きます。
GCE上のDebianにWordPressをインストール
ところで、MacでSSH使ってると、Broken Pipeでしょっちゅう切れませんか? そんな時はSSH接続前に、Macのターミナルで、あああああ下記の設定を入れましょう。
ishigami-air:~ susumuis$ vim .ssh/config ServerAliveInterval 15
ではDebianということで、aptを更新しましょう。
susumuis@instance-1:~$ sudo aptitude update susumuis@instance-1:~$ sudo aptitude safe-upgrade
さて、LAMP環境をインストールしましょう。Ubuntuだったらここで、taskselで一発でしたね。 ということで、
susumuis@instance-1:~$ sudo aptitude tasksel
すると、下記の警告が。。。。
perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = "ja_JP.UTF-8" are supported and installed on your system.
さきに、日本語環境をインストールしましょう。
susumuis@instance-1:~$ sudo dpkg-reconfigure locales
[*] ja_JP.UTF-8 UTF-8
を選びます。
それでは気を取り直して
susumuis@instance-1:~$ sudo aptitude tasksel
すると、期待に反して、
パッケージの設定 ┌──────────────────────────────────┤ ソフトウェアの選択 ├──────────────────────────────────┐ │ 以下の定義済みソフトウェアコレクションからインストールするものを 1 つ以上選択できます。 │ │ │ │ インストールするソフトウェアの選択: │ │ │ │ [ ] Debian desktop environment │ │ [*] Web server │ │ [ ] Print server │ │ [ ] SQL database │ │ [ ] DNS Server │ │ [ ] File server │ │ [ ] Mail server │ │ [ ] SSH server │ │ [ ] Laptop │ │ │ │ │ │ <了解> │ │ │ └──────────────────────────────────────────────────────────────────────────────────────────┘
UbuntuみたいにLAMP環境みたいな便利なのは出てこないのですね。。。 SQL databaseを選んでも何が入るかわからないので、とりあえず、Web serverだけ入れて、 あとはaptから入れることにします。
<了解>
を押して、しばらく待つと処理が終わったようです。本当にapacheが入ったか見てみましょう。
susumuis@instance-1:~$ ls /etc/init.d/ README checkfs.sh google hostname.sh mountall-bootclean.sh mountnfs.sh rc rsync ssh umountnfs.sh acpid checkroot-bootclean.sh google-accounts-manager hwclock.sh mountall.sh mtab.sh rc.local rsyslog sudo umountroot apache2 checkroot.sh google-address-manager killprocs mountdevsubfs.sh networking rcS sendsigs udev urandom bootlogs cron google-startup-scripts kmod mountkernfs.sh ntp reboot single udev-mtab bootmisc.sh generate-ssh-hostkeys halt motd mountnfs-bootclean.sh procps rmnologin skeleton umountfs
3行目にapache2
が入っていますね!再起動してみましょう。
susumuis@instance-1:~$ sudo service apache2 restart [ ok ] Restarting web server: apache2 ... waiting .
できました!アクセスしてみましょう。そのためには、GCEのfirewallの設定を変更しなければいけません。
Developers Consoleから プロジェクト > プロジェクト名 > Compute Engine > ネットワーク をクリックし、 すべてのネットワーク
の下にある default
リンクをクリックすると、出てくる画面で、 ファイアウォールルール
の新規作成
をクリックします。
名前は適当でよいですが "default-http"
ソース範囲は "0.0.0.0/0"
許可対象プロトコル/ポートは "tcp:80"
にしました。
それでは、インスタンスのIPアドレスに対してブラウザからアクセスしてみます。 そうすると、
It works!
と表示されたと思います。ついでですので、本当に動いているか、ちょっと遊んでみましょう。
susumuis@instance-1:~$ sudo vim /var/www/index.html
ここで編集したとおりの内容が反映されると思います。
それでは引き続き、php, mysql(いわゆるLAMP環境)を入れてみます。
susumuis@instance-1:~$ sudo aptitude install mysql-server 以下の新規パッケージがインストールされます: heirloom-mailx{a} libaio1{a} libdbd-mysql-perl{a} libdbi-perl{a} libhtml-template-perl{a} libmysqlclient18{a} libnet-daemon-perl{a} libplrpc-perl{a} mysql-client-5.5{a} mysql-common{a} mysql-server mysql-server-5.5{a} mysql-server-core-5.5{a} psmisc{a} 更新: 0 個、新規インストール: 14 個、削除: 0 個、保留: 3 個。 10.2 M バイトのアーカイブを取得する必要があります。展開後に 98.5 M バイトのディスク領域が新たに消費されます。 先に進みますか? [Y/n/?] Y
MySQLのインストール後は、mysql_secure_installation
を使うと良いようなので、やってみます。
susumuis@instance-1:~$ mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. You already have a root password set, so you can safely answer 'n'. Change the root password? [Y/n] n ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed! Not critical, keep moving... - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] ... Success! Cleaning up... All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!
こうですか?わかりません>< 本番環境構築するときはもうちょっと深くMySQL勉強したほうが良さそうですね。
次に、PHPを入れてみます。
susumuis@instance-1:~$ sudo aptitude install php5 php-pear php5-mysql 以下の新規パッケージがインストールされます: apache2-mpm-prefork{ab} libapache2-mod-php5{a} libonig2{a} libqdbm14{a} libxml2{a} php-pear php5 php5-cli{a} php5-common{a} php5-mysql sgml-base{a} xml-core{a} 更新: 0 個、新規インストール: 12 個、削除: 0 個、保留: 3 個。 7,506 k バイトのアーカイブを取得する必要があります。展開後に 23.4 M バイトのディスク領域が新たに消費されます。 以下のパッケージには満たされていない依存関係があります: apache2-mpm-worker : 競合: apache2-mpm[仮想パッケージです] apache2-mpm-prefork : 競合: apache2-mpm[仮想パッケージです] 以下のアクションでこれらの依存関係の問題は解決されます: 以下のパッケージを削除する: 1) apache2-mpm-worker この解決方法を受け入れますか? [Y/n/q/?]Y
こんな感じでしょうか。だんだん怪しくなってきたぞ (^^;
不要かもしれないけど、なんとなく、apacheを再起動してみます。
susumuis@instance-1:~$ sudo service apache2 restart
PHPが入ってるか、phpinfoを表示してみます。
susumuis@instance-1:~$ cd /var/www/ susumuis@instance-1:/var/www$ sudo vi test.php
test.phpには
<?php phpinfo() ?>
と書いておきます。ブラウザでhttp://IPアドレス/test.php
にアクセスすると。。。
あ、ちゃんとphpinfoでますね!確認したらphpinfoはさっさと削除してしまいます。
susumuis@instance-1:/var/www$ sudo vi test.php
次にちゃんとmysqlが入ったかどうか遊んでみます。
susumuis@instance-1:/var/www$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 50 Server version: 5.5.35-0+wheezy1 (Debian) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec) mysql> create database ishigami; Query OK, 1 row affected (0.00 sec) mysql> use ishigami; Database changed mysql> show tables; Empty set (0.00 sec) mysql> create table ishigami ( id integer primary key, name text ); Query OK, 0 rows affected (0.01 sec) mysql> show tables; +--------------------+ | Tables_in_ishigami | +--------------------+ | ishigami | +--------------------+ 1 row in set (0.00 sec) mysql> select * from ishigami; Empty set (0.00 sec) mysql> insert into ishigami (id, name) values (1, 'susumu'); Query OK, 1 row affected (0.00 sec) mysql> select * from ishigami; +----+--------+ | id | name | +----+--------+ | 1 | susumu | +----+--------+ 1 row in set (0.00 sec) mysql> quit; Bye
問題なさそうです!
一度、この先も一回のエントリで書いたのですが、長くなったので分割します。 それでは次回に続きます。