準備
WrodPressのダウンロード
# wget https://ja.wordpress.org/latest-ja.tar.gz
# tar zxvf latest-ja.tar.gz
# mv wordpress /var/www/vhosts/[バーチャルホストのFQDN]
wordpressのドキュメントルートは、今後のnginxの運用で決めたディレクトリにした。
mariadbの設定
今回のバーチャルホストで使うwordpress用のデータベースを用意する。データベース名はドメイン名にした(例えば、example.comだったら、example)。
mysql -u root -p
MariaDB [(none)]>create database example;
この他root以外のwordpress専用のmysqlのユーザーも作成しました。
nginxとphp-fpmの設定
こちらで作成したバーチャルホスト専用の設定ファイルに、php-fpmnの設定を追加します。
# vi /etc/nginx/conf.d/example.com.conf
以下をserverディレクティブの後半に追記。
# wordpress パーマネントリンク設定
try_files $uri $uri/ /index.php?q=$uri&$args;
# wp-config.phpへのアクセス拒否設定
location ~* /wp-config.php {
deny all;
}
# php-fpm用設定
location ~ \.php$ {
root /var/www/vhosts/example.com/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
確認とリスタート。
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# systemctl restart nginx.service
WordPressの設定
# cd /var/www/vhosts/example.com/wordpress
# cp -p wp-config-sample.php wp-config.php
# vi wp-config.php
以下はデータベースに関する設定の箇所です。
define('DB_NAME', 'wordpress用に作成したデータベース名');
define('DB_USER', 'wordpress用に作成したデータベースのユーザ名');
define('DB_PASSWORD', 'ユーザーのパスワード');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
また、設定ファイルに認証用のユニークキーの設定もしました。以下の、「put your unique phrase here」の箇所に任意の文字列を設定します。
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');
いちいち設定するの面倒なので、こちらのサイトにアクセスすると勝手に定義を作成してくれるので、コピペして設定ファイルの該当部分にまるっと貼り付けるだけです。
動作確認
http://[ドメイン]/wp-admin/install.php
にアクセスしてログイン画面が表示されれば、サーバーサイドでの作業は一旦完了で、後は画面の指示に従ってインストールを進めていきます。