LoginSignup
2
0

More than 3 years have passed since last update.

初心者がWordPress環境構築してみた(単一構成)

Last updated at Posted at 2020-09-07

事前準備

EC2インスタンスを作成

SSH接続

$ssh -i .ssh/key.pem ec2-user@public_ip

※key.pemはssh_key

※public_ipはインスタンスのpublic_ip

Apacheのインストール

  • Apachのインストール・起動
$ sudo yum install -y httpd
$ sudo systemctl start httpd

MySQL5.7のインストール

MySQL Yum RepositoryからMySQL5.7をインストールする。

  • Yumリポジトリの情報のインストール
$ sudo yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
  • MySQL8.0リポジトリを無効にし、MySQL5.7リポジトリを有効にする
$ sudo yum-config-manager --disable mysql80-community
$ sudo yum-config-manager --enable mysql57-community
#適用されているか確認
$ cat /etc/yum.repos.d/mysql-community.repo
  • MySQLのインストール・起動
$ sudo yum install -y mysql-community-server
$ sudo systemctl start mysqld
  • MySQLの初期パスワードの確認
$ sudo cat /var/log/mysqld.log | grep root@localhost
[Note] A temporary password is generated for root@localhost: 12桁の文字列
  • MySQLのパスワード変更
$ mysqladmin -uroot -p password
Enter password:古いパスワード
New password:新しいパスワード
Confirm new password:新しいパスワード
#Warnigがでても変更はできています
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

Passwordのポリシーについて

  • WordPress用のDB・ユーザーを作成する
$ mysql -uroot -p
Enter password:設定したパスワード
#WordPress用のユーザー作成
mysql> CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'wordpressユーザーのパスワード';
#WordPress用のDB作成
mysql> CREATE DATABASE `wordpress`;
#DB権限を作成したユーザーに付与
mysql> GRANT ALL PRIVILEGES ON `wordpress`.* TO "wordpress"@"localhost";
#設定反映
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

PHP7.4のインストール

sudo yum install phpを実行すると、PHP5.4がインストールされてしまします。

Amazon LinuxのリポジトリにPHP5.4しかないためです。

amazon-linux-extrasを使用することで解決できます。

  • amazon-linux-extrasが存在するかの確認
$ which amazon-linux-extras
/usr/bin/amazon-linux-extras
  • amazon-linux-extrasがインストールされていない場合は、インストールを行う
$ sudo yum install -y amazon-linux-extras
$ sudo yum update -y
  • amazon-linux-extrasからPHP7.4をインストールする
$ sudo amazon-linux-extras install -y php7.4
$ sudo yum clean metadata
#追加でパッケージをインストール(必要なければ不要です。)
$ sudo yum install -y php-mbstring php-xml
$ sudo yum update -y

WordPressのインストール

  • WordPressをインストール
#インストールしたいディレクトリに移動
$ cd ~
$ wget http://ja.wordpress.org/latest-ja.zip
$ unzip latest-ja.zip
#サンプルをコピー
$ cp wordpress/wp-config-sample.php wordpress/wp-config.php
$ sudo vim wordpress/wp-config.php

#DBの設定値を変更する。
define( 'DB_NAME', 'database_name_here' );
define( 'DB_USER', 'username_here' );
define( 'DB_PASSWORD', 'password_here' );
define( 'DB_HOST', 'localhost' );

#セキュリティーキーの変更する。
define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

※セキュリティキーはオンラインジェネレータ を使用してください。

  • Apachの設定

Amazon Linuxの場合、 .htaccess がディフォルトで無効となっているため設定を行う必要がある。

実際の親ファイル/etc/httpd/conf/httpd.confではなくconf.dに設定を記載する。

$ sudo vim /etc/httpd/conf.d/file_name.conf

#「sample」にはアクセスしたいURIを指定
#「/home/ec2-user/wordpress/」にはインストールしたディレクトリを指定する
Alias /sample/ /home/ec2-user/wordpress/
<Directory "/home/ec2-user/wordpress">
  AllowOverride All
  Options None
  Require all granted
  #ipを制限する場合に記載
  Require ip ××××××××××××
</Directory>

#Apache文法の確認
$ sudo httpd -t
Syntax OK
$ sudo systemctl restart httpd
  • http://ホスト/sample/にアクセスしてWordPressの初期設定画面が開ければ成功です!

  • アクセスした際に403エラーとなる場合は権限設定を行う。

#実行権限の付与
#「/home/ec2-user」にはインストールしたディレクトリを指定する
$ sudo chmod o+x /home/ec2-user

間違っている点があればお教えください!

続き

冗長化構成

参考

Amazon Linux による WordPress ブログのホスティング

CentOS7にyumでMySQL5.7最新版をインストールする

AWS EC2(Amazon Linux)にPHP7.4をインストール

2
0
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
2
0