日本語Wordpressサイトにはインストールに必要な環境として以下のようになっています。
「PHP バージョン 7 以上、MySQL バージョン 5.6 以上 または MariaDB バージョン 10.0 以上 古い PHP や MySQL しか利用できないレガシーな環境でも、PHP 5.2.4 以上、かつ MySQL 5.0 以上であれば WordPress は動作しますが、公式サポートは終了しており、サイトがセキュリティの脆弱性にさらされる危険があります。」
したがってPHPやMariaDBについてはCentOS標準ではなく、別のリポジトリからダウンロードしてインストールします。

最初に古いバージョンがインストールされていないか調べて、もしあれば削除します。
# rpm -qa |grep httpd
# rpm -qa |grep php
# rpm -qa |grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
# yum remove mariadb-libs
削除しました:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                                             
依存性の削除をしました:
  postfix.x86_64 2:2.10.1-6.el7

postfixが必要な場合は、後で再インストールします

epelリポジトリをインストールします
# yum -y install epel-release

普段はepelを無効にして、使う時は明示的にコマンドで指定することにします
# vi /etc/yum.repos.d/epel.repo
enabled=1

enabled=0

remiのgpgキーをインポートします
# rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi

CentOS7用のremiリポジトリをインストールします
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

普段はremiを無効にして、使う時は明示的にコマンドで指定することにします
enabled=1

enabled=0
# vi /etc/yum.repos.d/epel.repo
# vi /etc/yum.repos.d/remi.repo
# vi /etc/yum.repos.d/remi-safe.repo

httpdをインストールします
# yum search httpd --enablerepo=remi
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
# yum search mod_ssl --enablerepo=remi
mod_ssl.x86_64 : SSL/TLS module for the Apache HTTP Server

# yum install --enablerepo=remi  httpd.x86_64 httpd-devel.x86_64 httpd-manual.noarch httpd-tools.x86_64 mod_ssl.x86_64

PHPを検索します
# yum search php --enablerepo=remi-php71
======================================== N/S matched: php ========================================
php.x86_64 : PHP scripting language for creating dynamic web sites
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-devel.x86_64 : Files needed for building PHP extensions
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php-intl.x86_64 : Internationalization extension for PHP applications
php-json.x86_64 : JavaScript Object Notation extension for PHP
php-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling
php-mysql.x86_64 : A module for PHP applications that use MySQL databases
php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
php-odbc.x86_64 : A module for PHP applications that use ODBC databases
php-pear.noarch : PHP Extension and Application Repository framework
php-soap.x86_64 : A module for PHP applications that use the SOAP protocol
php-xml.x86_64 : A module for PHP applications which use XML
php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
php-opcache.x86_64 : The Zend OPcache
php-pecl-apcu.x86_64 : APC User Cache
php-pecl-apcu-bc.x86_64 : APCu Backwards Compatibility Module
php-pecl-apcu-devel.x86_64 : APCu developer files (header)
以下省略

phpをインストールします
# yum -y install --enablerepo=remi,remi-php71 php php-devel  php-mysql php-mbstring php-gd  php-xmlrpc php-xml php-intl php-soap php-pecl-apcu.x86_64 php-pecl-zendopcache.x86_64 php-pear php-opcache.x86_64 php-pecl-apcu.x86_64 php-pecl-apcu-devel.x86_64 php-pecl-apcu-devel.x86_64
インストール:
  php.x86_64 0:7.1.10-1.el7.remi               php-devel.x86_64 0:7.1.10-1.el7.remi             
  php-gd.x86_64 0:7.1.10-1.el7.remi            php-intl.x86_64 0:7.1.10-1.el7.remi              
  php-mbstring.x86_64 0:7.1.10-1.el7.remi      php-mysqlnd.x86_64 0:7.1.10-1.el7.remi           
  php-opcache.x86_64 0:7.1.10-1.el7.remi       php-pear.noarch 1:1.10.5-2.el7.remi              
  php-pecl-apcu.x86_64 0:5.1.8-1.el7.remi.7.1  php-pecl-apcu-devel.x86_64 0:5.1.8-1.el7.remi.7.1
  php-soap.x86_64 0:7.1.10-1.el7.remi          php-xml.x86_64 0:7.1.10-1.el7.remi               
  php-xmlrpc.x86_64 0:7.1.10-1.el7.remi      

依存性関連をインストールしました:
  gd-last.x86_64 0:2.2.5-1.el7.remi           php-cli.x86_64 0:7.1.10-1.el7.remi                
  php-common.x86_64 0:7.1.10-1.el7.remi       php-json.x86_64 0:7.1.10-1.el7.remi               
  php-pdo.x86_64 0:7.1.10-1.el7.remi          php-pecl-apcu-bc.x86_64 0:1.0.3-6.el7.remi.7.1    
  php-process.x86_64 0:7.1.10-1.el7.remi    

MariaDB 10のインストールのためにリポジトリを追加します。
# vi /etc/yum.repos.d/mariadb.repo
# MariaDB 10.2 CentOS repository list - created 2017-10-03 06:10 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

# yum install MariaDB-server MariaDB-client

# systemctl restart httpd.service
# systemctl enable httpd.service

httpd(Apache)の設定をします
Webサイトデータを載せるディレクトリを /data/html にしました。
# mkdir /data (データを載せるディレクトリを作ります)
# mkdir /data/html (ドキュメントルートに設定するディレクトリを作ります)

# cd /etc/httpd/conf (httpdの設定ファイルがあるディレクトリに移動します)
# ls
# cp httpd.conf httpd.conf.org (一応、オリジナルの設定ファイルを名前を付けてコピー保存しておきます)
# vi httpd.conf (設定ファイルを修正します)

DocumentRoot “/var/www/html”
 ↓
DocumentRoot “/data/html”    <?-こちらに修正

<Directory “/var/www/html”>
 ↓
<Directory “/data/html”>     <?-こちらに修正

DirectoryIndex index.html
 ↓
DirectoryIndex index.php index.html  <?-こちらに修正

mimetypeの設定追加をします
# vi /etc/mime.types
application/x-httpd-php                php
application/x-httpd-php-source    phps

phpの設定をします

phpのログを記録するディレクトリを作ります
# mkdir /var/log/php
# chown apache:apache /var/log/php (apacheから書き込めるようにします)
# chmod 755 /var/log/php

オリジナルの設定ファイルを残しておきます
# cp /etc/php.ini /etc/php.ini.org


phpの設定ファイルを修正します
# vi /etc/php.ini
;date.timezone =
 ↓
date.timezone = 'Asia/Tokyo'

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
 ↓
error_reporting = E_ALL & ~E_NOTICE

;error_log = php_errors.log
 ↓
error_log = "/var/log/php/php_errors.log" (さきほど作ったディレクトリにログを残すようにします)

memory_limit = 128M
 ↓
memory_limit = 256M

post_max_size = 8M
 ↓
post_max_size = 51M

upload_max_filesize = 2M
 ↓
upload_max_filesize = 51M

;mbstring.language = Japanese
 ↓
mbstring.language = Japanese

;mbstring.internal_encoding = EUC-JP
 ↓
mbstring.internal_encoding = UTF-8

;mbstring.http_input = auto
 ↓
mbstring.http_input = pass

;mbstring.http_output = SJIS
 ↓
mbstring.http_output = pass

;mbstring.encoding_translation = Off
 ↓
mbstring.encoding_translation = Off

;mbstring.detect_order = auto (そのまま)

;mbstring.substitute_character = none
 ↓
mbstring.substitute_character = none;

;mbstring.func_overload = 0
 ↓
mbstring.func_overload = 0

;mbstring.strict_detection = On
 ↓
mbstring.strict_detection = Off

# cd /data/html (httpdのドキュメントルートに移動します)
# vi test.php (phpが本当に動くかチェック用のファイルを作ります)
下記の3行を記入します。
<?php
phpinfo();
?>

phpの設定変更を反映させるためにhttpdをリスタートします
# systemctl restart httpd

# firewall-cmd --list-all-zones (開いているポートをチェック)
# firewall-cmd --add-service=http --zone=public --permanent
# firewall-cmd --add-service=https --zone=public --permanent
# firewall-cmd --add-service=smtp --zone=public --permanent

# firewall-cmd --reload (変更した設定をリロードします)
# firewall-cmd --list-all-zones (本当に変更されたか?一応チェックします)


ブラウザでこのサーバーにアクセスしてPHPテスト画面が出ればOKです。
http://( FQDN )/test.php

MaiaDBの設定をします
CentOS7からMySQLの代わりにMariadbが標準になりました。実際の使い勝手はMySQLと同じようです。
# systemctl start mariadb (データベースサーバーをスタートします)
# systemctl enable mariadb (パワーONでOSが立ち上がるとmariadbも自動で立ち上がるように設定します)

# mysql_secure_installation (mariadbの初期設定をします)
Enter current password for root (enter for none):
Set root password? [Y/n] Y
New password:  (適当なパスワード)
Re-enter new password:(適当なパスワード)
Remove anonymous users? [Y/n]Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n]  Y
Reload privilege tables now? [Y/n] Y
Thanks for using MariaDB!

オリジナルの設定ファイルを残しておきます
# cp /etc/my.cnf /etc/my.cnf.org

データベースフォーマットを指定します
MariaDBの設定ファイルに下記のような追記を行います。
# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
innodb_file_per_table = 1
innodb_file_format = Barracuda
innodb_large_prefix
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
max_allowed_packet = 10M
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4

MariaDBをリスタートして設定変更を反映します。
# systemctl restart mariadb.service

# mysql -u root -p(先ほど設定したパスワード) (rootで入ります)
全員にパスワードが設定されているか確認します。
> select host,user,password from mysql.user;
たとえばWordPress用のデータベースwordpressを作ります。
> create database wordpress character set utf8mb4 COLLATE utf8mb4_unicode_ci; 
> show databases;
> exit

ログの保存期間をデフォルトの4週間から約1年に延長します
# vi /etc/logrotate.conf
# keep 4 weeks worth of backlogs
rotate 4
 ↓
rotate 54

Maildir方式でメイルデータを保存する設定になっているとmailコマンドでメイルが見られない
各ユーザーのホームディレクトリで環境設定
# vi  ~/.bash_profile
export MAIL=$HOME/Maildir  追加

変更を読み込みます
# source !$

日本語WordPress をダウンロードしてインストールします。
https://ja.wordpress.org/

# tar xvfz wordpress-4.8.2-ja.tar.gz
# cp -r wordpress /data/html/wordpress

# cd /data/html/wordpress
# cp wp-config-sample.php wp-config.php
データベース関係の設定を記入します
# vi wp-config.php
/** WordPress のためのデータベース名 */
define('DB_NAME', 'database_name_here');

/** MySQL データベースのユーザー名 */
define('DB_USER', 'username_here');

/** MySQL データベースのパスワード */
define('DB_PASSWORD', 'password_here');

/** MySQL のホスト名 */
define('DB_HOST', 'localhost');

/** データベースのテーブルを作成する際のデータベースの文字セット */
define('DB_CHARSET', 'utf8');

define('DB_CHARSET', 'utf8mb4');

/**
 * WordPress データベーステーブルの接頭辞
 *
 * それぞれにユニーク (一意) な接頭辞を与えることで一つのデータベースに複数の WordPress を
 * インストールすることができます。半角英数字と下線のみを使用してください。
 */
$table_prefix  = 'wp_';

プラグインをインストールしようとすると、FTPのアカウントを要求される場合は、下記の設定を記入します
define('FS_METHOD','direct');

設定がすんだら下記のURLにブラウザでアクセスしてインストールを開始します。

http://[FQDN]/wordpress/wp-admin/install.php

プラグインのインストールをするときに「インストールに失敗しました: ディレクトリを作成できませんでした。 /data/html/wordpress/wp-content」といわれた場合はパーミッションを変更します。

必要ならば先に削除されたpostfixをインストールします。
# yum install postfix


最終更新日時: 2023年 10月 13日(金曜日) 10:42