お名前.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セットアップ画面が表示されます。