1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Cloud9でWordPress環境を構築 2

Last updated at Posted at 2021-01-16

WordPressの学習&AWSに触れるのを目的として
AWS Cloud9でWordPress環境を構築するまでの備忘録。

ここまでやったこと

  • AWSアカウント登録
  • Cloud9環境立ち上げ
  • MySQLインストール

この記事の目次

  • MySQLセットアップ
  • 初期設定
  • データベース作成
  • サービス起動
  • 最新化
  • サービス起動
  • スナップショット作成
  • 作成手順
  • 復元手順

(スナップショットを作成するのは
この後のWordPressのセットアップが上手くいかないから……)

MySQLセットアップ

初期設定

セットアップ前にログからrootのパスワードを確認する。


$ sudo cat /var/log/mysqld.log | grep "A temporary password"
2021-01-16T09:30:18.257989Z 1 [Note] A temporary password is generated for root@localhost: XXXXXXXXX 

ログイン後、パスワードの変更が要求される。
デフォルトのパスワードポリシー:数字/大文字/小文字/特殊文字を各1つ以上使用、長さは8文字以上
https://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html

$ mysql_secure_installation

# ログで確認したパスワード
Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

# パスワードの変更を要求される
New password: (新しいパスワード)

# rootのパスワードを変更するか?
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N

# 匿名ユーザを削除するか?
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y

# rootでのリモートログインを禁止するか?
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y

# テストデータベースを削除するか?
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y

# 今すぐ権限テーブルを読み込むか?
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

All done! 

文字コードをUTF-8に、
パスワードの有効期限は無期限に変更しておく。2行追加。

$ sudo vi /etc/my.cnf

[mysqld]
(省略)
character-set-server = utf8
default_password_lifetime = 0

# サービス再起動しておく
$ sudo service mysqld restart

データベース作成

rootでMySQLにログイン、WordPress用のデータベース&ユーザを作成する。


$ mysql -u root -p
Enter password: 

# WordPress用のデータベース作成
mysql> CREATE DATABASE データベース名;
Query OK, 1 row affected (0.01 sec)

# ユーザ作成
mysql> GRANT ALL PRIVILEGES ON *.* TO 'ユーザ名'@'localhost' IDENTIFIED BY '作成ユーザのパスワード';

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit

サービス起動

最新化

MySQLよりに先に確認すべきだったかも。ただ、結果的には最新化不要。

# OS 結果:アップデート不要
$ sudo yum -y update
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
261 packages excluded due to repository priority protections
No packages marked for update

# Apache 結果:アップデート不要
$ sudo yum install -y httpd24
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                                       | 3.7 kB  00:00:00     
261 packages excluded due to repository priority protections
No package httpd24 available.
Error: Nothing to do

# PHP 結果:アップデート不要
$ sudo yum install -y php56
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
261 packages excluded due to repository priority protections
No package php56 available.
Error: Nothing to do

サービス起動

Apache、MySQLのサービスを起動する。

# Apache起動 (起動済だったかも)
$ sudo service httpd start 
$ sudo service httpd status
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/httpd.service.d
           └─php-fpm.conf
   Active: active (running)

# MySQL起動 (起動済だったかも)
$ sudo service mysqld start
$ sudo service mysqld status
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) 

スナップショット作成

作成手順

ここまでで一旦、EC2のスナップショットを作成しておく。

EC2 > Elastic Block Store からスナップショットを作成する。
Select resource type は Volume にする。
※ 1インスタンス、1ボリューム状態なのでどちらでも変わりなし

復元手順

復元手順は次の通り。(未実施)

  1. スナップショットからボリュームを作成
  2. インスタンスを停止
  3. インスタンスから復元したいボリュームをデタッチ
  4. アタッチするインスタンスのルートデバイスを確認
  5. 1で作成したボリュームをインスタンスにアタッチ
  6. インスタンス起動

次、WordPressインストールなど。
Cloud9でWordPress環境を構築 3

前の記事へのリンク
Cloud9でWordPress環境を構築 1

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?