WordPress にデフォルトで含まれているテーマ Twenty Ten がかっこいいなと思ったので、「林檎生活100」をそのテーマで運用するために Amazon EC2 にインストールしてみました。
その手順は下記のとおりです。
1. Amazon EC2 インスタンス起動
Amazon EC2 のインスタンスを下記のパラメーターで起動します。EC2 のパラメーターは、各自の環境で柔軟に決めてください。
- AMI: Amazon Linux AMI 2012.03 (64bit)
- Instance Type: t1.micro
- Security Group:
- TCP 22 (SSH) 0.0.0.0/0
- TCP 80 (HTTP) 0.0.0.0/0
- TCP 443 (HTTPS) 0.0.0.0/0
なお、WordPress は、同一サイト内でも絶対アドレスが基本となり、記事内の画像ファイルへのリンクなどは絶対アドレスのままデータベースに格納されます。そのため、ドメインが変わってしまうと画像ファイルが表示されないというようなことが起きるので、EC2 インスタンスに Elastic IP アドレスを付与し、運用時に使用するドメインでアクセスすることをおすすめします。
ちなみに、「林檎生活100」では、Elastic IP アドレスを付与しないで運用しています。その詳細は、今後の記事で説明する予定です。
次に、起動した EC2 インスタンスに ec2-user でログインし、下記のコマンドでアップデートを実施します。
$ sudo yum update
これで、インスタンスの初期設定まで完了です。
2. MySQL インストール
EC2 インスタンスにログインした状態で、下記のコマンドを入力し、MySQL をインストールします。さらに、自動起動の設定をしたあと起動し、初期設定を実施します。
$ sudo yum install mysql-server $ sudo chkconfig mysqld on $ sudo service mysqld start $ sudo /usr/bin/mysql_secure_installation
初期設定では、推奨される選択肢を Enter を押すことで選択していけばいいと思います。MySQL のルートパスワードは必ず設定しましょう。
そのあと、mysql コマンドで MySQL にログインし、WordPress 用のデータベースを次のコマンドで作成します。
$ mysql -uroot -p > create database wordpress character set utf8; > grant all on wordpress.* to wordpress@localhost identified by '********'; > exit
アスタリスクで記述した wordpress ユーザーのパスワードは、各環境で自由に設定してください。
3. Apache インストール
次に、Apache をインストールします。WordPress の管理画面には SSL でアクセスしたいので、mod_ssl も合わせてインストールします。Apache の SSL 設定は、インストール時に生成される証明書で自動的に設定されます。管理画面のための SSL ということで、その設定をそのまま利用します。
$ sudo yum install httpd $ sudo yum install mod_ssl
さらに、.htaccess で URL Rewriting の設定ができるように、httpd.conf の339行目の AllowOverride を None から All に変更します。これは、WordPress でパーマリンクの設定をデフォルトから変更する場合に必要になります。
$ sudo cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.20120615 $ sudo vim /etc/httpd/conf/httpd.conf $ diff -u /etc/httpd/conf/httpd.conf.20120615 /etc/httpd/conf/httpd.conf --- /etc/httpd/conf/httpd.conf.20120615 2012-06-14 20:41:27.604761766 +0000 +++ /etc/httpd/conf/httpd.conf 2012-06-14 20:42:20.042761638 +0000 @@ -336,7 +336,7 @@ # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # - AllowOverride None + AllowOverride All # # Controls who can get stuff from this server.
設定変更は、設定ファイルのコピーを取得したあと、設定ファイルを編集し、変更した部分を diff で比較するという方法で行っています。
設定が完了したら、Apache を下記のコマンドで自動起動の設定をしたあと、起動します。
$ sudo chkconfig httpd on $ sudo service httpd start
EC2 インスタンスの Public DNS に、HTTP と HTTPS でアクセスし、Apache の Welcome ページが表示されることを確認してください。
Clik here to view.

Test Page for the Apache HTTP Server on Amazon Linux AMI
4. PHP インストール
次に、PHP をインストールします。PHP スクリプトから MySQL へ接続するためのエクステンションも同時にインストールします。今回は、MySQL Native Driver を使用しています。
$ sudo yum install php $ sudo yum install php-mysqlnd
PHP を有効にするために、Apache を再起動します。
$ sudo service httpd restart
5. WordPress インストール
最後に、WordPress をインストールします。まず、最新版の WordPress をホームディレクトリにダウンロードし、展開します。インストール時は、WordPress 3.4 が最新版でした。
$ wget http://wordpress.org/latest.zip $ unzip latest.zip
展開したディレクトリ内にある設定ファイルのサンプルをリネームし、設定ファイルを編集します。
$ mv wordpress/wp-config-sample.php wordpress/wp-config.php $ vim wordpress/wp-config.php
少し長いですが、下記に設定ファイルを掲載します。
<?php /** * The base configurations of the WordPress. * * This file has the following configurations: MySQL settings, Table Prefix, * Secret Keys, WordPress Language, and ABSPATH. You can find more information * by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing * wp-config.php} Codex page. You can get the MySQL settings from your web host. * * This file is used by the wp-config.php creation script during the * installation. You don't have to use the web site, you can just copy this file * to "wp-config.php" and fill in the values. * * @package WordPress */ // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'wordpress'); /** MySQL database password */ define('DB_PASSWORD', 'wordpress'); /** MySQL hostname */ define('DB_HOST', 'localhost'); /** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8'); /** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', ''); /**#@+ * Authentication Unique Keys and Salts. * * Change these to different unique phrases! * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. * * @since 2.6.0 */ define('AUTH_KEY', 'T%w[2Va]!)%QuUUYPq!nAEyR5+ra.%+j/[7+j==X >.G]ys-|3~.wEz{E-+^Fv M'); define('SECURE_AUTH_KEY', '.JF0qIcvjR?8fy95dhaqLRfW$ULe7uS;{L +!-o+~53|0wfq%L+1iYZU:=@|mh4X'); define('LOGGED_IN_KEY', '#Xb[t x~-g=N-4LlFwxf:ey+}*.}sji,Bx-n0&?b8+[k9 ;{kWl b)<a2i`9g&Wt'); define('NONCE_KEY', 'sJ8i0TAv:Y5|[-ZhU3dLo_+PzR+St@tkv+Ubt5)5Ph0VuM~#%!EgMJ|AxPEwGE`O'); define('AUTH_SALT', '6W}][eC?e2CgG3`5d7uUz.fd@0zlBq Sp.zY&/#mS79q>1X(BitxsdI([k#Qwg2K'); define('SECURE_AUTH_SALT', 'J=hUk4B/H@Nh3t_$^Alf0 )xT&Bj9=]X`<&%j`5bU++(b|%->zE=/sqt;.G-K $n'); define('LOGGED_IN_SALT', 'uaW@X!Sd2PNZ8=~J~}aRa4u]+oT8@J`d|Up$+%-sv)LKr;?lSmw+v= 5,uuNX&tO'); define('NONCE_SALT', ':*A?M()e1qTt*.qGgH@0QxCBWwfL*qygG7;)4^&d/[:_9!oij8lFnfw9xIubOJH@'); /**#@-*/ /** * WordPress Database Table prefix. * * You can have multiple installations in one database if you give each a unique * prefix. Only numbers, letters, and underscores please! */ $table_prefix = 'wp_'; /** * WordPress address (URL) */ define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME']); /** * Blog address (URL) */ define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME']); /** * WordPress Localized Language, defaults to English. * * Change this to localize WordPress. A corresponding MO file for the chosen * language must be installed to wp-content/languages. For example, install * de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German * language support. */ define('WPLANG', ''); /** * For developers: WordPress debugging mode. * * Change this to true to enable the display of notices during development. * It is strongly recommended that plugin and theme developers use WP_DEBUG * in their development environments. */ define('WP_DEBUG', false); /** * To Force SSL Logins and SSL Admin Access */ define('FORCE_SSL_ADMIN', true); /* That's all, stop editing! Happy blogging. */ /** Absolute path to the WordPress directory. */ if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/'); /** Sets up WordPress vars and included files. */ require_once(ABSPATH . 'wp-settings.php');
変更点は、下記のとおりです。
・MySQL settings
MySQL のインストールで作成した wordpress データベース名と wordpress ユーザー名とそのパスワードを設定してください。
・Authentication Unique Keys and Salts.
下記の URL で生成される認証ユニークキーとソルトをコピーアンドペーストしてください。
https://api.wordpress.org/secret-key/1.1/salt/
・WordPress address (URL)
この設定は通常不要です。「林檎生活100」では、EC2 インスタンスにインストールした WordPress に Elastic IP アドレスを付与していないため、インスタンスを停止させたあとに、起動することで Public DNS が変化してしまいます。それによって WordPress アドレスに差異が生じて閲覧できなくなってしまうため、このような設定をしています。
・Blog address (URL)
この設定は通常不要です。WordPress アドレスの理由と同様です。
・To Force SSL Logins and SSL Admin Access
ログインと管理画面での作業を SSL で暗号化することを強制する設定です。
ここまで設定したら、wordpress ディレクトリの内容を /var/www/html にコピーします。また、/var/www/html とその中のディレクトリやファイルの所有者を apache ユーザーに設定します。
sudo cp -a wordpress/* /var/www/html sudo chown -R apache:apache /var/www/html
すべてのターミナルでの作業が完了したら、Web ブラウザで EC2 インスタンスの Public DNS にアクセスし、WordPress の初期設定を行います。
Clik here to view.

WordPress › Installation
この画面では、下記の項目をフォームに入力し、Install WordPress をクリックします。
- Web サイトタイトル
- ユーザー名
- パスワード
- メールアドレス
Clik here to view.

WordPress › Installation
Log In をクリックします。
Clik here to view.

林檎生活100 › Log In
初期設定で入力したユーザー名とパスワードでログインします。
そうすると、下記のような管理画面のダッシュボードにアクセスできます。記事の投稿などはこの管理画面から実施します。
Clik here to view.

Dashboard ‹ 林檎生活100 — WordPress
ここで改めて、Web ブラウザで EC2 インスタンスの Public DNS にアクセスすると、下記のような Web サイトが表示されるはずです。
Clik here to view.

林檎生活100 | Just another WordPress site
これで、WordPress のインストールは完了です。基本的に、管理画面からの操作だけで、記事の投稿やページの編集のみならず、WordPress のアップデートやプラグインのインストール、テーマの編集、PHP や CSS、JavaScript ファイルの編集までできてしまいます。
管理画面からの操作は直感的なので、いろいろ試しながら Web サイトを構築してもらえたらなと思います。