CentOS7, nginx1.11, php7-fpm, MySQL5.7でWordPress動かす

さくらVPS上の CentOS7で、nginx, php7, php-fpm, MySQL5.7, UNIXドメインソケットでWordePressを動かす。

ドメインは未設定で、IPからアクセスする。

さくらVPSにCentOS7をインストールしたときにやる設定

CentOS7にyumでnginx1.11をインストール

CentOS7にyumでPHP7, PHP-FPM, OPcache, APCuをインストール

nginx + php-fpmでCentOS7でPHP7を最低限動かす

CentOS7 + nginx + php7-fpm + UNIXドメインソケットでPHP動かす

CentOS7にMySQL5.7をyumでインストール

WordPressをインストール・設定

インストールする場所は自由、本家サイトからダウンロード。

cd /usr/share/nginx/
sudo wget https://ja.wordpress.org/latest-ja.tar.gz
sudo tar zxfv latest-ja.tar.gz

wordpressディレクトリが作成されているので、所有者をnginxユーザに変更。

sudo chown -R nginx:nginx wordpress

WordPressのDB設定する。
念のため元ファイルはコピーしておく。

cd wordpress
sudo cp wp-config-sample.php wp-config.php

設定ファイルを修正する。

sudo vim wp-config.php
/** WordPress のためのデータベース名 */
define('DB_NAME', 'test_wordpress');

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

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

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

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

まとめると、

公開ディレクトリは「/usr/share/nginx/wordpress」
DBは「/usr/share/nginx/wordpress/wp-config.php」で設定したものになる。

これをnginxとMySQLに設定していく。

nginxの設定

rootディレクティブは、wordpressディレクトリを配置したところを指定する。

try_filesディレクティブは、WordPress用のパーマネントリンクを設定しておく。

server {
    listen 80;
    server_name localhost;

    root /usr/share/nginx/wordpress;
    index index.php;

    # wordpress パーマネントリンク設定
    try_files $uri $uri/ /index.php?q=$uri;

    # wp-config.phpへのアクセス拒否設定
    location ~* /wp-config.php {
        deny all;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php-fpm/php7.sock;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        include fastcgi_params;
    }
}

設定ファイルの構文をチェックする。

sudo nginx -t

問題なければnginx再起動。

sudo systemctl restart nginx

mysqlの設定

MySQLへログインする。

mysql -u root -p

WordPress用のデータベース作成。

mysql> create database test_wordpress;

今回はrootユーザを設定したけど、WordPress用のユーザを作成したほうがセキュアだ。

設定した場合はここでそのユーザを作成しておこう。

WordPressにアクセス

初回設定画面には、IPからでもアクセスできる。

301 Moved Permanently

設定が終わると、ログイン出来るようになる。

301 Moved Permanently

普通にIPからもトップページを確認できる。

2022 XXX Directory: Sex, Porn & XXX Cam Sites Listing
XXX.xxx is the world's leading free porn directory. Choose from thousands of hardcore sex sites with streaming video, high quality photos and live sex cam.

参考

CentOS7 + php7 + nginx + php-fpm環境にwordpressインストール

CentOS7 に Nginx をインストールする

Nginx + PHP-FPM で WordPress を動かす

コメント

タイトルとURLをコピーしました