WordPress実行環境(LAMP)の構築
WordPressを実行するためには、以下のソフトウェアが必要です。
- Apache HTTPd Server (Webサーバー)
- MySQL
- PHP
導入していきます!
sudo yum install -y httpd mod_ssl php php-mysql php-xml mysql-server
MySQLの設定
MySQLを起動します。
sudo service mysqld start
以下のようなメッセージが出て、起動すると思います。
01 | Initializing MySQL database: Installing MySQL system tables... |
06 | To start mysqld at boot time you have to copy |
07 | support-files/mysql.server to the right place for your system |
09 | PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! |
10 | To do so, start the server, then issue the following commands: |
12 | /usr/bin/mysqladmin -u root password 'new-password' |
13 | /usr/bin/mysqladmin -u root -h motounagiya password 'new-password' |
15 | Alternatively you can run: |
16 | /usr/bin/mysql_secure_installation |
18 | which will also give you the option of removing the test |
19 | databases and anonymous user created by default. This is |
20 | strongly recommended for production servers. |
22 | See the manual for more instructions. |
24 | You can start the MySQL daemon with: |
25 | cd /usr ; /usr/bin/mysqld_safe & |
27 | You can test the MySQL daemon with mysql-test-run.pl |
28 | cd /usr/mysql-test ; perl mysql-test-run.pl |
30 | Please report any problems with the /usr/bin/mysqlbug script! [ OK ] |
31 | Starting mysqld: [ OK ] |
次にDBのパスワード設定などを行います。
以下のコマンドを実行します。
sudo /usr/bin/mysql_secure_installation
MySQLのrootパスワードを設定します。
01 | NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL |
02 | SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! |
04 | In order to log into MySQL to secure it, we'll need the current |
05 | password for the root user. If you've just installed MySQL, and |
06 | you haven't set the root password yet, the password will be blank, |
07 | so you should just press enter here. |
09 | Enter current password for root (enter for none): ← 最初は空なので何も入力せずEnter |
10 | OK, successfully used password, moving on... |
12 | Setting the root password ensures that nobody can log into the MySQL |
13 | root user without the proper authorisation. |
15 | Set root password? [Y/n] Y ← ここでrootのパスワードを設定します |
18 | Password updated successfully! |
19 | Reloading privilege tables.. |
22 | By default, a MySQL installation has an anonymous user, allowing anyone |
23 | to log into MySQL without having to have a user account created for |
24 | them. This is intended only for testing, and to make the installation |
25 | go a bit smoother. You should remove them before moving into a |
26 | production environment. |
28 | Remove anonymous users? [Y/n] Y |
31 | Normally, root should only be allowed to connect from 'localhost'. This |
32 | ensures that someone cannot guess at the root password from the network. |
34 | Disallow root login remotely? [Y/n] Y |
37 | By default, MySQL comes with a database named 'test' that anyone can |
38 | access. This is also intended only for testing, and should be removed |
39 | before moving into a production environment. |
41 | Remove test database and access to it? [Y/n] Y |
42 | - Dropping test database... |
44 | - Removing privileges on test database... |
47 | Reloading the privilege tables will ensure that all changes made so far |
48 | will take effect immediately. |
50 | Reload privilege tables now? [Y/n] Y |
55 | All done! If you've completed all of the above steps, your MySQL |
56 | installation should now be secure. |
58 | Thanks for using MySQL! |
WordPress用のMySQLユーザーとデータベース作成
以下の内容でMySQLデータベースを作成します。あくまで“サンプル”ですので、本番では複雑なパスワードを設定されることをオススメします!
DB名 |
wordpressdb |
DBユーザー名 |
wpdbuser |
DBパスワード |
Password |
例:
サンプル情報を元に「SQLファイル」を以下のように作成します。
wpcreate.sql:
1 | CREATE DATABASE wordpressdb DEFAULT CHARACTER SET utf8; |
2 | CREATE USER 'wpdbuser'@'localhost' IDENTIFIED BY 'Password'; |
3 | GRANT ALL PRIVILEGES ON wordpressdb.* TO wpdbuser@localhost; |
MySQLに接続して、上記SQLを実行します。
mysql -u root -p
上記が一番簡単な方法ですが、以下の方法でも作成可能です。
完了したら、以下のコマンドでMySQLの接続を切っておきましょう。
1 | mysql> quit ← mysqlから抜ける |
WordPressのインストール
今回、
http://DNS名/wordpress/
へインストールを行います、以下の手順で進めます。
- Webサーバのルートディレクトリ「/var/www/html」に移動
- WordPressの最新版をwgetコマンドでダウンロード
- tarコマンドでダウンロードしたファイルを展開
- chownコマンドで所有者権限をapacheユーザーへ変更
以下、コマンドのみで記載します。
3 | sudo tar zxf latest-ja.tar.gz |
4 | sudo chown -R apache.apache wordpress |
エンドポイントの設定
WordPressの公開及び管理のために、エンドポイントを追加します。
を追加します。
再度「Microsoft Azure 管理ポータル」にアクセスして、自分が作成した「Linux仮想マシン名」をクリックして以下の画面を表示します。
メニューから「エンドポイント」を選択します。
(クリックで拡大)
この画面に切り替わります。ここでは、「+ 追加」を選択します。
(クリックで拡大)
ここでは、「スタンドアロン エンドポイントの追加」を選択して、右下の矢印で「次へ」
(クリックで拡大)
「名前」から「HTTP」を選択します。
(クリックで拡大)
「HTTP」です。
(クリックで拡大)
他の項目は自動で入力されます。ので、このまま右下の「チェック」をクリックします。
(クリックで拡大)
この画面に切り替わって、完了まで数秒待ちます。
完了したら同様に「HTTPS」も追加します。
(クリックで拡大)
ブラウザで「DNS名」にアクセスして、アクセス可能か確認してみます。
この画面が表示されれば、完了です。
(クリックで拡大)
WordPressの管理の安全上
の設定は実施しておきましょう。
WordPressの設定
それでは、WordPressのインストール設定をしていきます。
httpdとmysqldを起動します。
1 | sudo service httpd start |
2 | sudo service mysqld start |
その後、
http://DNS名/wordpress/
へアクセスして、以下の画面が表示されることを確認します。
「設定ファイルを作成する」で次の画面へ
(クリックで拡大)
ここは先ほど設定した、データベースの情報用意します。
そして、「さあ、始めましょう!」で次の画面へ
(クリックで拡大)
こちらにデータベースの接続情報を入力します。
が入力の項目で、他はそのままで大丈夫です。「送信」で次へ
(クリックで拡大)
今度は、「インストール実行」で次へ
(クリックで拡大)
次に、サイトの設定です。
サイト名 |
好みのものを入力(例:Tuning Maniax) |
ユーザー名 |
好みのものを入力(admin以外が好ましい) |
パスワード |
複雑なもので設定しましょう |
メールアドレス |
自分のメールアドレス(パスワードを忘れた時に必要です) |
プライバシー |
今回はコンテスト用なので、「チェックを外します」 |
以下は、例です。
すべての項目が入力完了したら、「WordPressをインストール」で次へ
(クリックで拡大)
この画面が出れば、WordPressのインストールは完了です!
(クリックで拡大)
念の為に管理画面にログインしておきましょう。
https://DNS名/wordpress/wp-admin/
と、HTTPSでアクセスを推奨します。
先ほど設定した、
を使って、ログインしましょう
(クリックで拡大)
この画面が表示されば、問題ありません!
(クリックで拡大)
最後に、サイトのトップページにアクセスしてみます。 http://DNS名/wordpress/
(クリックで拡大)
ここまで、表示されればインストールに問題はありません。
競技用データのインポート
WordPressのインストール後、公式サイトに掲載されている手順に沿ってWordPressのデータをインポートしましょう。
WordPressのデータをインポートする - Tuning Maniax 2014
データがインポートできない時は?
※上記手順でデータがうまくインポートできない場合、PHPのXMLモジュールがインストールされていない可能性があります。例えばCentOSであれば以下のようにXMLモジュールをインストールして、Apacheをリスタートしてください。
sudo yum -y install php-xml
sudo service httpd restart
これが終われば競技前の準備完了です。お疲れ様でした!
【参考リンク】
Tuning Maniax 2014 - 蒼き調律者たち
Windows Azure 自習書シリーズ - 仮想マシン (IaaS) 編 | MSDN
<編集部より> MacからのSSH接続やSQLファイルの作成など、わかりづらかった箇所の追記を行いました。その他、一部の間違いを修正しました。(2014.05.17)