現在位置: ホーム / みらくるブログ / 【ゼロから始める MIRACLE LINUX】MIRACLE LINUX に WordPress を導入しよう

【ゼロから始める MIRACLE LINUX】MIRACLE LINUX に WordPress を導入しよう

今回は、いよいよ WordPress を導入するまでの手順をご紹介します。MIRACLE LINUX のインストールがまだの方は Web サーバー構築編のリンクから手順をご確認ください。

Web サーバー構築編

MIRACLE LINUX に Web サーバーを構築し、WordPress を導入するまでの手順をご紹介します。

 

使用環境

・MIRACLE LINUX 8.4 (GUIインストール)
・WordPress 6.0.2 

WordPress 用ユーザーの作成

以下のコマンドを実行し、WordPress 用のユーザを作成します。
今回はユーザーを ’worduser’として作成しています
’worduser’には任意のユーザー名、 'user-pass' にはパスワードを入力してください。

# mysql -u root -p
mysql> create user worduser@localhost identified by 'user-pass';
Query OK, 0 rows affected (0.01 sec)

ユーザーの作成が出来ていることを以下のコマンドを実行し確認します。

# mysql -u worduser -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.26 Source distribution
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> select user(), current_user();
+--------------------+--------------------+
| user() | current_user() |
+--------------------+--------------------+
| worduser@localhost | worduser@localhost |
+--------------------+--------------------+
1 row in set (0.00 sec)

ユーザーが問題なく作成されていることが確認出来たら、一度 root ユーザに切り替えます。
以下のコマンドを実行し、作成したユーザーに データベース(wordpress)の全ての権限を付与します。

mysql> grant all privileges on wordpress.* to worduser@localhost;
Query OK, 0 rows affected (0.01 sec)

ここまでで WordPress のインストール前の準備は完了です。

WordPress のインストール

まず公式サイトにアクセスし、以下の画像の赤丸部分から tar.gz ファイルをダウンロードします。

ダウンロードした tar ファイルを展開します。

# ls
wordpress-6.0.2-ja.tar.gz
# tar -xzvf wordpress-6.0.2-ja.tar.gz
wordpress/
wordpress/wp-login.php
wordpress/wp-cron.php
wordpress/xmlrpc.php
wordpress/wp-load.php
wordpress/wp-admin/
wordpress/wp-admin/credits.php
wordpress/wp-admin/admin-functions.php
:
:

ファイルの展開後、以下のディレクトリへ移動させます。

# mv wordpress /var/www

以下のコマンドを実行し、wordpress の権限を apache ユーザーに付与します。

# ls -ls
合計 12
4 drwxr-xr-x. 2 root root 4096 8月 29 17:16 cgi-bin
4 drwxr-xr-x. 2 root root 4096 8月 29 17:16 html
4 drwxr-xr-x. 5 root root 4096 9月 8 14:30 wordpress
# chown -R apache.apache /var/www/wordpress
# ls -ls
合計 12
4 drwxr-xr-x. 2 root root 4096 8月 29 17:16 cgi-bin
4 drwxr-xr-x. 2 root root 4096 8月 29 17:16 html
4 drwxr-xr-x. 5 apache apache 4096 9月 8 14:30 wordpress

Apache の設定ファイル(/httpd.conf)の修正を行います。

# vi /etc/httpd/conf/httpd.conf
==========以下ファイル内容==========
:
:
DocumentRoot "/var/www/wordpress"
#
# Relax access to content within /var/www.
#
<Directory "/var/www/wordpress">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
:
:

設定が完了したら、以下のコマンドを実行し Apache の再起動を行います。

# systemctl restart httpd

ブラウザを開いて「http://[ サーバの IP アドレス ]」にアクセスすると以下のような画面が表示されます。

「さあ、始めましょう!」をクリックすると以下の画面が表示されるため、冒頭で作成を行ったユーザー名とパスワードを入力して送信を押します。

wp-config.php に書き込みできない場合は、手動で wp-config.php を作成し、画面に表示されている PHP 文をコピーしてください。

vi 等のエディターで以下の場所にファイルを作成し、テキストを貼り付けてください。 

# vi /var/www/wordpress/wp-config.php

ファイルを作成後、web の画面で「インストール実行」をクリックすると以下の画面に遷移するため、情報を入力します。
情報を入力し終わったら「WordPress をインストール」をクリックし実行してください。

インストールが完了すると以下の画面が表示されます。

ログインを選択し、ユーザー名およびパスワードを入力すると管理画面が表示されます。
ただし、まだ SSL の設定を行っていないため保護されていない通信となっています。

ssl1

SSL の導入

ここからは SSL の導入方法について紹介します。

1.ファイアウォールの設定

httpds を利用するために以下のコマンドを実行し、ポートを解放します。

# firewall-cmd --add-port=443/tcp --permanent
success
# firewall-cmd --reload
success

以下のコマンドを実行すると、解放されているポートの一覧が表示されます。
443 ポートが解放されていることが確認できます。

# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3
sources:
services: cockpit dhcpv6-client ssh
ports: 80/tcp 443/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

2.秘密鍵の作成

以下のコマンドを実行し、秘密鍵の作成を行います。
openssl パッケージがインストールされていない場合は dnf コマンドでインストールしてください。

# openssl genrsa > server.key
Generating RSA private key, 2048 bit long modulus (2 primes)
........................+++++
......................+++++
e is 65537 (0x010001)

3.CSRファイルの作成

以下のコマンドを実行し、CSR ファイルの作成を行います。
今回はテストで作成するので情報の記載はせず Enter キーで飛ばしていますが、本来であれば情報を記載をしてください。

# openssl req -new -key server.key > server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

4.証明書の作成

以下のコマンドを実行し、証明書を作成します。

# openssl x509 -req -signkey server.key < server.csr > server.crt
Signature ok
subject=C = XX, L = Default City, O = Default Company Ltd
Getting Private key

5.ssl.conf の編集

/etc/httpd/conf.d/ssl.conf の記述を変更します。
今回は秘密鍵および証明書を /etc/httpd/conf に配置しているのでそのようにパスを書き換えます。

# vi /etc/httpd/conf.d/ssl.conf
==========以下記述内容==========
:
:
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateFile /etc/httpd/conf/server.crt
:
:
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCertificateKeyFile /etc/httpd/conf/server.key
:
:

準備が完了したら、以下のコマンドを実行し Apache の再起動を行います。

# systemctl restart httpd 

6.管理画面での設定

ブラウザを開き「http://[ サーバの IP アドレス ]」にアクセスし、管理画面を開きます。
設定タブをクリックし、http://hogehoge となっている URL を https://hogehoge に書き換えます。

ssl2

7.SSL動作確認

ブラウザを開き「https://[ サーバの IP アドレス ]」にアクセスすると以下の画面が表示されたら設定が出来ていることが分かります。

ssl3

安全ではないと出ていますが、アクセスをすると以下のようにサンプルページが表示されます。
URL 部分の「保護されていない通信」をクリックすると以下のようなポップアップが表示されます。
今回はオレオレ証明書を使用しているため「証明書が無効です」という表示がされていますが、証明書の設定自体は完了していることが分かります。

ssl4

「証明書が無効です」という箇所をクリックすると以下の画像のように登録を行った証明書の詳細が確認できます。

ssl5

おわりに

いかがでしょうか。実際に今回構築したWebサーバーをインターネット上公開する際にはインターネットに公開可能な環境の用意やドメインの設定などが必要となりますが、サーバーを構築する具体的な手順をイメージ頂けたかと思います。実際にインターネット上でWebサーバーを構築する手順なども順次公開予定ですのでご期待ください。また、本記事の不明点などあれば、MIRACLE LINUX関連ページのユーザーフォーラムからお問い合わせください。

MIRACLE LINUX 関連ページ

MIRACLE LINUX に興味を持っていただけたら、ぜひ以下のページも合わせてご確認ください!

タグ: