お名前.com VPS OSインストールからWordPressインストールまで CentOS7.0編

f:id:arcright:20150215143711p:plain

CentOS7インストール

f:id:arcright:20150308002514p:plain

CentOS7インストール後

# yum -y update
# yum -y install vim-enhanced wget

SELinux無効化

# setenforce 0
# vim /etc/selinux/config
enforcing -> disabledに変更する

Nginx

# cd /etc/yum.repos.d
# vim nginx.repo
nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
Nginxインストール
# yum -y install nginx
Nginx設定
# cd /etc/nginx/conf.d
# cp default.conf wordpress.conf
# vim wordpress.conf
--- default.conf 2014-09-16 22:54:29.000000000 +0900
+++ wordpress.conf 2015-03-08 00:15:38.815000000 +0900
@@ -1,14 +1,12 @@
server {
listen 80;
- server_name localhost;
+ server_name 111.111.111.111; (VPSのグローバルIP)

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

- location / {
- root /usr/share/nginx/html;
- index index.html index.htm;
- }
+ root /var/www/wordpress;
+ index index.php index.html index.htm;

#error_page 404 /404.html;

@@ -27,13 +25,12 @@

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
- #location ~ \.php$ {
- # root html;
- # fastcgi_pass 127.0.0.1:9000;
- # fastcgi_index index.php;
- # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- # include fastcgi_params;
- #}
+ location ~ \.php$ {
+ fastcgi_pass 127.0.0.1:9000;
+ fastcgi_index index.php;
+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+ include fastcgi_params;
+ }

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
Nginx起動,自動起動
# systemctl start nginx
# systemctl enable nginx

MariaDB

MariaDBインストール
# yum -y install mariadb-server
MariaDB起動,自動起動
# systemctl start mariadb
# systemctl enable mariadb
データベース作成,ユーザ作成
# mysql -u root
MariaDB [(none)]>CREATE DATABASE wordpress;
MariaDB [(none)]>GRANT ALL PRIVILEGES ON wordpress.* TO wpuser@localhost IDENTIFIED BY "password";
MariaDB [(none)]>exit

PHP

PHP,ライブラリインストール
# yum -y install php php-mysql php-mbstring php-gd php-fpm

PHP-GDはWordPressで画像リサイズ、編集するときに使うライブラリみたいだった。

PHP-FPM設定
# vim /etc/php-fpm.d/www.conf
apache -> nginxに変更
PHP-FPM起動,自動起動
# systemctl start php-fpm
# systemctl enable php-fpm

WordPress

WordPressダウンロード
# cd /var/www
# wget https://ja.wordpress.org/wordpress-4.1.1-ja.tar.gz
# tar xvzf wordpress-4.1.1-ja.tar.gz
# chown -R nginx:nginx wordpress

所有権を変更しておかないとディレクトリ作成ができなくて画像アップロードとかができない。

WordPress設定
# cd wordpress
# cp wp-config-sample.php wp-config.php
# vim wp-config.php
--- wp-config-sample.php 2015-02-19 23:24:18.000000000 +0900
+++ wp-config.php 2015-03-08 00:19:20.054000000 +0900
@@ -21,13 +21,13 @@

// ** MySQL 設定 - この情報はホスティング先から入手してください。 ** //
/** WordPress のためのデータベース名 */
-define('DB_NAME', 'database_name_here');
+define('DB_NAME', 'wordpress');

/** MySQL データベースのユーザー名 */
-define('DB_USER', 'username_here');
+define('DB_USER', 'wpuser');

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

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

firewalld

HTTP通信を許可
# firewall-cmd --permanent --add-service=http
# systemctl reload firewalld

80ポートでの通信を許可する。これで該当IPにアクセスするとWordPressセットアップ画面が表示される。

お名前.com VPS OSインストールからWordPressインストールまで Ubuntu14.04 LTS編

f:id:arcright:20150308024650p:plain
Ubuntu 14.04 LTSからapt1.0が導入されているのでaptコマンドを使用していきます。

$ sudo apt update
$ sudo apt install openssh-server

以降、sshで接続して作業を行います。

$ sudo apt install vim

Nginx

PPA追加

標準のリポジトリにもNginxパッケージは存在しますが、バージョン1.4.6で想像していたよりも古かったのでPPAを追加して最新安定版をインストールします。
PPA追加の為に用いるadd-apt-repositoryコマンドですがUbuntu14.04ではsoftware-properties-commonをインストールすると使用できます。

$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:nginx/stable
Nginxインストール
$ sudo apt update
$ sudo apt install nginx
Nginx設定

Debian系ディストリビューションではサイト毎の設定を/etc/nginx/site-availableに配置し、/etc/nginx/site-enabledにシンボリックリンクを作成することで設定を有効にします。
今回はデフォルトで作成されているdefaultを編集します。

/etc/nginx/site-available/default

--- default.org	2015-03-08 02:15:35.498809000 +0900
+++ default	2015-03-08 02:23:32.834809000 +0900
@@ -27,10 +27,10 @@
 	#
 	# include snippets/snakeoil.conf;
 
-	root /var/www/html;
+	root /var/www/wordpress;
 
 	# Add index.php to the list if you are using PHP
-	index index.html index.htm index.nginx-debian.html;
+	index index.php index.html index.htm index.nginx-debian.html;
 
 	server_name _;
 
@@ -42,14 +42,14 @@
 
 	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 	#
-	#location ~ \.php$ {
-	#	include snippets/fastcgi-php.conf;
+	location ~ \.php$ {
+		include snippets/fastcgi-php.conf;
 	#
 	#	# With php5-cgi alone:
 	#	fastcgi_pass 127.0.0.1:9000;
 	#	# With php5-fpm:
-	#	fastcgi_pass unix:/var/run/php5-fpm.sock;
-	#}
+		fastcgi_pass unix:/var/run/php5-fpm.sock;
+	}
 
 	# deny access to .htaccess files, if Apache's document root
 	# concurs with nginx's one

fastcgiに関する設定は/etc/nginx/snippets/fastcgi-php.confにまとめられたのでincludeを有効にすればオッケーです。
今回はphp-fpmを使用するのでUNIXソケットを使用した設定を有効にします。

Nginx再起動

設定を有効にする為に再起動しておきます。

$ sudo service nginx restart

MySQL

MySQLインストール
$ sudo apt install mysql-server

CentOS7では標準リポジトリからMySQLがなくなりMariaDBに変更されましたが、Ubuntu14.04ではMySQLもMariaDBも両方あります。今回はMySQLを入れます。

データベース作成,ユーザ作成
# mysql -u root
mysql>CREATE DATABASE wordpress;
mysql>GRANT ALL PRIVILEGES ON wordpress.* TO wpuser@localhost IDENTIFIED BY "password";
mysql>exit

PHP

PHP,ライブラリインストール
$ sudo apt install php5 php5-mysql php5-fpm php5-gd
PHP-FPM

PHP-FPMの設定ファイルはデフォルトのままでnginxでも動作するので設定変更する必要はないです。
ちなみに設定ファイルは/etc/php5/fpm/pool.d/www.confにあります。

WordPress

WordPressダウンロード
$ cd /var/www
$ sudo wget https://ja.wordpress.org/wordpress-4.1.1-ja.tar.gz
$ sudo tar xvzf wordpress-4.1.1-ja.tar.gz
$ chown -R www-data:www-data wordpress
WordPress設定
$ sudo cd wordpress
$ sudo cp wp-config-sample.php wp-config.php
$ sudo vim wp-config.php
--- wp-config-sample.php 2015-02-19 23:24:18.000000000 +0900
+++ wp-config.php 2015-03-08 00:19:20.054000000 +0900
@@ -21,13 +21,13 @@

// ** MySQL 設定 - この情報はホスティング先から入手してください。 ** //
/** WordPress のためのデータベース名 */
-define('DB_NAME', 'database_name_here');
+define('DB_NAME', 'wordpress');

/** MySQL データベースのユーザー名 */
-define('DB_USER', 'username_here');
+define('DB_USER', 'wpuser');

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

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

VPSのIPにアクセスするとWordPressセットアップ画面が表示されます。