wordpress4.5の環境が必要になったのでインストールする手順を書いておく。

※nginxのfast cgiを使う方法も追記(2016/07/02)

環境

  • httpd v2.4.6 or nginx v1.10.1
  • MariaDB v15.1
  • PHP v5.4.16
  • Wordpress v4.5.2

構築

今回はCentOS7でhttpd (or nginx) + wordpress + MariaDBを使う。操作はすべてrootユーザで実行する。
nginxを使う場合はhttpのインストール手順は飛ばす。

初期設定

細かい設定。

OSアップデート。

$ su -
root$ yum update -y

firewall-cmdでhttpを許可する。

root$ firewall-cmd --add-service=http --zone=public --permanent
root$ firewall-cmd --reload

SELinuxを無効化しておかないと画面が確認できませんでした。ハマるポイントなのでご注意を。

root$ setenforce 0
root$ vi /etc/sysconfig/selinux
SELINUX=disabled
に変更

レポジトリ追加。

root$ yum install -y epel-release
root$ yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

PHPをインストール

root$ yum install -y php php-common php-devel php-mbstring php-pear php-fpm php-mysql php-gd php-xml
root$ php --version
PHP 5.4.16(略)

httpdインストール

※nginxのfast cgiiの構成を使う場合はこの手順は不要。

httpdをインストールして、自動起動設定をする。
Wordpressをインストールしてから起動するのでここでは起動しない。

root$ yum install httpd -y
root$ systemctl enable httpd

nginxインストール

※httpdを使う場合はこの手順は不要。
nginxをインストールしてfast cgiの設定をする。

root$ yum install -y http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
root$ yum install -y nginx
root$ systemctl enable nginx
root$ systemctl start nginx
root$ vi /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
index index.php ;
root /var/www/wordpress ;

charset utf-8;

location / {
try_files $uri $uri/ @wordpress;
}

location ~ \.php$ {
try_files $uri @wordpress;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/wordpress$fastcgi_script_name;
include fastcgi_params;
}

location @wordpress {
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/wordpress/index.php;
include fastcgi_params;
}

#access_log /var/log/nginx/log/host.access.log main;

#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
root$ nginx -t
root$ systemctl enable php-fpm
root$ vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx

Unix domain Socket使ったほうが速いらしいので興味があればphp-fpmの設定ファイルとnginxの設定ファイルのfastcgi_passをSocketファイルに変更すべし。

MariaDBインストール

今回はbaseレポジトリのMariaDB5.5系を使います。最新のMariaDBやMySQLが使いたい場合はレポジトリを設定して適当に読み替えてください。

root$ yum install mariadb mariadb-devel mariadb-server -y
root$ mysql --version
mysql Ver 15.1 Distrib 5.5.47-MariaDB, for Linux (x86_64) using readline 5.1

CentOS6ではmysql-serverがあったのですが、CentOS7ではなくなっているようです。MariaDBはMySQLのforkでCentOS7からはmariadb-serverが標準となっているようです。

起動して、自動起動設定とDBの初期化をします。

root$ systemctl enable mariadb.service
root$ systemctl start mariadb.service
root$ mysql_secure_installation
Enter -> rootのパスワード設定 -> パスワード再入力 -> Y -> Y -> Y -> Y でOK。

wordpressで使うユーザとDBを作成します。
wordpressデータベース、wordpressユーザ、パスワードwordpressとしているので適宜変更してください。

root$ mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE wordpress;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress.* TO wordpress@localhost IDENTIFIED BY "wordpress";
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

wordpressインストール

公式サイトから最新版のWordpressをダウンロードしてインストールします。

root$ yum install wget -y
root$ wget https://ja.wordpress.org/wordpress-4.5.2-ja.tar.gz
root$ tar zxfv wordpress-4.5.2-ja.tar.gz
root$ mv wordpress /var/www/html/
root$ cd /var/www/html/wordpress/
root$ cp wp-config-sample.php wp-config.php
root$ vi wp-config.php
以下の部分をMariaDBのインストール時に設定したものに適宜変更する。
/** WordPress のためのデータベース名 */
define('DB_NAME', 'wordpress');
/** MySQL データベースのユーザー名 */
define('DB_USER', 'wordpress');
/** MySQL データベースのパスワード */
define('DB_PASSWORD', 'wordpress');

ジェネレータで生成された鍵を設定ファイルの下部に記載されているパラメータに設定する。

root$ vi wp-config.php
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');

wordpressに接続

httpdまたはnginxを起動して画面に接続する。

httpdの時。

root$ systemctl start httpd

nginxの時。

root$ systemctl start nginx
root$ systemctl start php-fpm

ブラウザでhttp://localhost/wordpressに接続すると以下の画面が表示される。表示されない場合は手順が抜けている可能性が高いのでhttpdやMariaDBのログを確認すると良い。

wordpressの設定については割愛。

終わり。