OS
CentSO7は最小パッケージでインストールを実施しています。初期設定を済ませてから設定を行ってください。

remiリポジトリの追加
「php7」は標準リポジトリに入って入ないのでリポジトリを追加します。
remiリポジトリのインストール
# yum -y install remi-release
「/etc/yum.repos.d」ディレクトリに「remi-php70.repo」「remi-safe.repo」「remi.repo」が作成されます。
後で必要になってくるパッケージ
# yum -y install wget
nginx + wordpress
nginx
nginxのインストール
# yum install nginx
nginxの設定
「/etc/nginx/conf.d」ディレクトリ内に、新規に設定ファイルを作成します。
# cd /etc/nginx/conf.d # vi rin-ka.conf
設定ファイルの変更
server { listen 80 default_server; server_name rin-ka.net; root /usr/share/nginx/wordpress; index index.php; # 413 Request Entity Too Large client_max_body_size 20M; # パーマネントリンク設定 try_files $uri $uri/ /index.php?$args; # wp-config.phpへのアクセス拒否設定 location ~* /wp-config.php { deny all; } # php-fpm用設定 location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; include fastcgi_params; } # クライアントキャッシュ # ログを除外 location ~ .*\.(jpg|gif|png|css|js|ico|woff) { expires 10d; access_log off; log_not_found off; } }
セキュリティや高速化にまつわる設定

nginx起動
設定ファイルの文法をチェックしてから、nginxを起動、自動起動設定を行います。
# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful # systemctl start nginx # systemctl enable nginx
wordpress
wordpressのインストール
# cd /usr/share/nginx/ # wget https://ja.wordpress.org/latest-ja.tar.gz # tar xzvf latest-ja.tar.gz # chown -R nginx:nginx wordpress
ドキュメントルートに移動し最新のファイルをダウンロードし解凍します。
解凍したディレクトリの所有者とグループを「nginx」に変更します。
php7
php7インストール
他に必要なものを一緒にインストールします。
# yum install --enablerepo=remi-php70,remi-safe php php-mbstring php-pear \ php-fpm php-mcrypt php-mysql \ php-gd php-opcache php-pecl-apcu-bc
「php-fpm」nginxと連携させるために必要です。
「php-gd」無くてもwordpressは動作しますが写真の加工の際に必要になります。インストールされていないとアイキャッチの縦横比率が狂いました。
「php-opcache」wordpressの高速化に利用します。
「php-pecl-apcu-bc」「php-pecl-apcu」wordpressの高速化に利用します。
php7の設定ファイルを編集
# cd /etc/ # vi php.ini
;バージョンを隠す expose_php = Off ;ファイルアップロードの上限サイズを変更 post_max_size = 20M upload_max_filesize = 20M ;タイムゾーンの指定 date.timezone = "Asia/Tokyo" ;文字コードの指定 mbstring.language = Japanese mbstring.internal_encoding = UTF-8 mbstring.http_input = auto
php-fpm
php-fpm設定
php-fpmの実行ユーザとグループが初期設定「apache」となっているので、実行ユーザとグループを「nginx」に変更します。
# cd /etc/php-fpm.d/ # vi www.conf
設定ファイルの変更
user = nginx group = nginx
php-fpm起動
php-fpmを起動、自動起動設定を行います。
# systemctl start php-fpm # systemctl enable php-fpm
MariaDB
mariadbのインストール、起動、自動起動設定
# yum install mariadb mariadb-server # systemctl start mariadb # systemctl enable mariadb
mariadbの初期設定
「root」ユーザパスワード設定、「anonymous」ユーザ、「test」データベースなどを削除します。
# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): <-- 「Enter」キーを押下 OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y <-- 「y」 New password: <-- rootユーザパスワード設定 Re-enter new password: <-- 再入力 Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y <-- 「y」 ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y <-- 「y」 By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y <-- 「y」 - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y <-- 「y」 Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
設定ファイルの変更
文字コードと各種パラメータを変更します。
[mysqld] character-set-server = utf8 innodb_buffer_pool_size = 512M query_cache_size = 64M
MariaDB再起動
設定を反映させるため再起動します。
# systemctl restart mariadb
wordpress用データベース作成
# mysql -u root -p Enter password: MariaDB [(none)]> CREATE DATABASE rinka; Query OK, 1 row affected (0.00 sec)
管理ユーザの作成
GRANT ALL PRIVILEGES ON DB名.* TO "user"@"localhost" IDENTIFIED BY "password"; FLUSH PRIVILEGES;
wordpress
wp-configの設定
# cd /usr/share/nginx/wordpress/ # vi wp-config.php
乱数はwordpress本家APIにアクセスしてして取得する。
/** WordPress のためのデータベース名 */ define('DB_NAME', 'rinka'); /** MySQL データベースのユーザー名 */ define('DB_USER', 'user'); /** MySQL データベースのパスワード */ define('DB_PASSWORD', 'password'); /**#@+ * 認証用ユニークキー * * それぞれを異なるユニーク (一意) な文字列に変更してください。 * {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org の秘密鍵 サービス} で自動生成することもできます。 * 後でいつでも変更して、既存のすべての cookie を無効にできます。これにより、す べてのユーザーを強制的に再ログインさせることになります。 * * @since 2.6.0 */ define('AUTH_KEY', 'ランダムな文字列'); define('SECURE_AUTH_KEY', 'ランダムな文字列'); define('LOGGED_IN_KEY', 'ランダムな文字列'); define('NONCE_KEY', 'ランダムな文字列'); define('AUTH_SALT', 'ランダムな文字列'); define('SECURE_AUTH_SALT', 'ランダムな文字列'); define('LOGGED_IN_SALT', 'ランダムな文字列'); define('NONCE_SALT', 'ランダムな文字列');