諸事情により、WordPress を再インスト-ルしなければならなくなったので。
過去の記事の通りにインスト-ルできなかったので改めて記載 (誰~、あの記事書いたの)。
手順は下記の通り。
- CentOS セットアップ
- Apache、PHP、MariaDB、sshd セットアップ
- SELinux 設定
- WordPress インスト-ル
1.CentOS セットアップ (省略)
理由も省略。
2.Apache、PHP、MariaDB、sshd セットアップ
1.epel リポジトリインスト-ル
yum install epel-release
2.remi リポジトリインスト-ル
rpm -Uvh rpms.famillecollet.com/enterprise/remi-release-7.rpm
3.Apache、PHP、MariaDB インスト-ル
yum install --enablerepo=remi,remi-php71 httpd mariadb mariadb-server php php-gd php-mbstring php-mysqlnd php-xml policycoreutils-python
*
php-xml は、プラグイン『Associates Link Builder』に必要なためにインスト-ルしている。
4.MariaDB ル-トパスワード設定
mysql -u root
update mysql.user set password=password('ル-トパスワ-ド') where user = 'root';
flush privileges;
exit;
5.WordPress 用DB作成
mysql -u root -p create database WordPress用DB名; grant all privileges on WordPress用DB名.* to WordPress用DBユ-ザ-名@localhost identified by 'パスワ-ド'; exit;
6.WordPress セットアップファイル配置
適当なディレクトリへWordPress書庫ファイルを配置し、ファイルを展開する。
tar -zxvf WordPress書庫ファイル
ドキュメントル-トとするディレクトリへ展開結果を配置する。
展開結果フォルダ直下の、『license.txt』、『readme.html』を削除する。
7.設定ファイル追加・削除・修正
『/etc/httpd/conf/httpd.conf』 の修正
119行目付近
# DocumentRoot "/var/www/html" DocumentRoot "ドキュメントル-トに指定するフルパス"
145行目付近
# Options Indexes FollowSymLinks Options FollowSymLinks
153行目付近
# AllowOverride None AllowOverride All
161行目付近
<LimitExcept GET POST HEAD>
Order deny,allow
Deny from all
</LimitExcept>
ファイル末尾に追記
ServerSignature Off ServerTokens ProductOnly
『/etc/httpd/conf.d/welecom.conf』、『/etc/httpd/conf.d/autoindex.conf』、『/etc/httpd/conf.d/userdir.conf』の削除
『/etc/httpd/conf.d/expires.conf』 を新規作成
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType text/html "access plus 0 seconds"
ExpiresByType application/atom_xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
</IfModule>
『/etc/httpd/conf.d/deflate.conf』 を新規作成
<IfModule mod_deflate.c>
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|ico) no-gzip dont-vary
SetEnvIfNoCase Request_URI _\.utxt$ no-gzip
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
</IfModule>
『/etc/php.ini』
374行目付近
# expose_php = On expose_php = Off
903行目付近
;date.timezone = date.time = "Asia/Tokyo"
8.各サ-ビスの自動起動設定 及び 起動
systemctl start httpd.service systemctl start mariadb.service systemctl enable httpd.service systemctl enable mariadb.service
9.ssh 鍵認証化
鍵認証で ssh ログインするユ-ザ-で以降の処理を実行する。
下記コマンドで 鍵を生成
ssh-keygen -t rsa
*
パスフレ-ズ入力が要求される。
生成された鍵ファイルの内、『id_rsa.pub』を『authorized_keys』にリネ-ムする。
生成された鍵ファイルの内、『id_rsa』を ssh ログインするマシンにコピ-する。
ssh 鍵認証でログインする場合は、下記コマンドを実行する。
ssh -i ./id_rsa ユ-ザ-ID@リモ-トマシンのIPアドレス または ホスト名
『/etc/ssh/sshd_config』の修正
79行目付近
#PasswordAuthentication yes PasswordAuthentication no
10.パケットフィルタリング設定
firewall-cmd --permanent --add-service=http firewall-cmd --reload
3.SELinux 設定
1.ポリシ-設定
以下のポリシ-をOnにする。
httpd_builtin_scripting
httpd_can_network_connect
httpd_unified
httpd_can_network_connect_db
ポリシ-のパラメ-タ値を確認するコマンド
getsebool -a | grep キ-ワ-ド
ポリシ-のパラメ-タ値を設定するコマンド
setsebool -P ポリシ-名=on
コンテキスト設定
semanage fcontext -a -t httpd_sys_content_t "WordPress配置ディレクトリ(/.*)?"
restorecon -R -v WordPress配置ディレクトリ
semanage fcontext -a -t httpd_sys_rw_content_t "WordPress配置ディレクトリ/wp-content(/.*)?"
restorecon -R -v WordPress配置ディレクトリ/wp-content
4.WordPressインスト-ル
1.WordPressインスト-ル
http://セットアップしたサ-バのIPアドレス
にアクセスしてインスト-ルする。
2.設定ファイル修正
『WordPress配置ディレクトリ.htaccess』
<Files ~ "^(wp-config\.php|xmlrpc\.php)$">
Order deny,allow
Deny from all
</Files>
<Files "wp-login.php">
Order deny,allow
Deny from all
Allow from アクセスを許すIPアドレス または ドメイン名
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>
*
# BEGIN WordPress の前に記載すること。
『WordPress配置ディレクトリ/wp-admin.htaccess』
Order deny,allow
Deny from all
Allow from アクセスを許すIPアドレス または ドメイン名
<FilesMatch "(admin-ajax.php)$">
Satisfy Any
Order allow,deny
Allow from all
Deny from none
</FilesMatch>
参考元
- Linux入門
- ITわかり隊
- CentOS7にPHP7をyumでインストールする
- Remi’s RPM repository – Packages
- Apacheセキュリティ設定
- はかいおうこうむてん
- WordPress Codex 日本語版
- web制作の覚え書き
- stackoverflow
- Server World


