0
0

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 5 years have passed since last update.

CentOS8.4&PHP7.4&mariaDBでWordpress5.8用の環境構築メモ

0
Last updated at Posted at 2021-08-08

WordPress最新バージョン(2021年8月現在)5.8環境を、Linux(CentOS8)上に構築した際のメモです。

  • システム要件

    • CentOS Linux release 8.4.2105
    • Apache/2.4.37
    • PHP 7.4.21
    • mysql Ver 15.1 Distrib 10.3.28-MariaDB, for Linux (x86_64) using readline 5.1
    • WordPress 5.8
  • 対象読者

    • 基本的なコマンド操作とvim操作は把握している前提とします。

おまじない

yum -y update

リポジトリの追加

yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

OS設定、必須ツールインストール

localectl set-locale LANG=ja_JP.UTF-8
timedatectl set-timezone Asia/Tokyo
yum -y install vim-enhanced
yum -y install mod_ssl
yum -y install git

rootユーザーのSSH接続を禁止にする

専用ユーザーの作成

useradd <ユーザー名>
passwd <ユーザー名>
<パスワード入力>

sshd_configの編集

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.org
/etc/ssh/sshd_config
# yesからnoへ修正
PermitRootLogin no
# sshdを再起動して設定反映
systemctl restart sshd

専用ユーザーでSSH接続できるか確認しましょう。

Apache

Apacheのインストール

# インストール
yum install httpd -y
# 起動
systemctl start httpd.service
# OS起動時に自動起動
systemctl enable httpd.service

設定ファイル(httpd.conf)の編集

# 元の設定ファイルはリネームして保存しておき
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.org
# vimコマンドで設定ファイルを開く
vim /etc/httpd/conf/httpd.conf
/etc/httpd/conf/httpd.conf
# indexファイルの拡張子に.phpを追加
DirectoryIndex index.php index.html

# Non を Allへ変更 (数カ所ある)
AllowOverride All 
# 設定ファイルの構文チェック
httpd -t
# エラーが出なければ再起動
systemctl restart httpd.service

PHP

PHP7.4のインストール

dnf -y install dnf-utils
dnf -y module install php:remi-7.4
yum install -y php-cli php-devel php-common php-mbstring php-fpm php-gd php-opcache php-pdo php-xml php-intl php-zip php-pear php-bcmath php-mysql

設定ファイル(php.ini)の編集

cp /etc/php.ini php.ini.org
/etc/php.ini
# 最低限
date.timezone = "Asia/Tokyo"

mariaDB

mariaDBインストール

# インストール
yum install -y mariadb-server
# 起動
systemctl start mariadb
# 自動起動を有効化
systemctl enable mariadb

セキュリティ強化(おまじない)

mysql_secure_installation
Enter current password for root (enter for none): 空でエンター
Set root password? [Y/n] 
<Yを入力して、rootパスワードの入力>

以降の質問は全部Y

文字コード設定

cp /etc/my.cnf.d/mysql-clients.cnf /etc/my.cnf.d/mysql-clients.cnf.org
cp /etc/my.cnf.d/mariadb-server.cnf /etc/my.cnf.d/mariadb-server.cnf.org
/etc/my.cnf.d/mysql-clients.cnf
[mysql]
default-character-set=utf8mb4
/etc/my.cnf.d/mariadb-server.cnf
[mysqld]
character-set-server=utf8mb4
# 再起動で設定反映
systemctl restart mariadb

rootにログイン

mysql -u root -p
<パスワード入力>

文字コード確認

show variables like "%char%";

DBと専用ユーザー作成、全権限付与

# DBを作成
create database <データベース名>;
# 全権限を持つDB専用ユーザーを作成
GRANT ALL PRIVILEGES ON <データベース名>.* to <ユーザー名>@localhost IDENTIFIED BY "<ユーザーパスワード>";
# 反映
FLUSH PRIVILEGES;
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?