Ubuntu14.04 + nginx でMT6.2.2を動かすまで
Ubuntu14.04 + nginx でMovable Type 6.2.2を動かすまで。
- 何はともあれ、たびたび、 apt-get update と apt-get upgrade は実行しましょう。
- ディレクトリの構成などは、あくまで一例ですので、それぞれの環境に置き換えて実行していってくださいな。
- Ubuntuは立ち上げたばかりくらいの想定です。
- 別にUbuntuに限らず他のLinuxディストリビューションでも問題ないかと思います。
nginxのインストール
apt-get install nginx
MTを入れる(mt-static以外)
/var/www/cgi-bin/mt へ。
MTを入れる(mt-static)
/var/www/mt-static へ。
ブログディレクトリを作成する
とりあえず /var/www/hogehoge とか。
MTディレクトリのパーミッション設定
cd /var/www/cgi-bin/mt/ chmod 755 *.cgi cd /var/www/mt-static/ chmod 777 support cd /var/www/ chmod 777 hogehoge
詳しくは本家MTサイト様へどうぞ。
Movable Type の設置 (Linux、BSD、Mac OS X)
http://www.movabletype.jp/documentation/mt6/installation/linux.html
※パーミッション設定いじってると、何か、「あー、cgiじゃー」っていう気分になりませんか。
nginxの設定
/etc/nginx/nginx.conf をいじりましょう。
nginxのconfまわりの設定次第なのですが、デフォルトのままでしたら、
/etc/nginx/sites-available/default なども。
rootディレクトリを /var/www とかに設定しつつ。
VirtualHostも一緒に設定する場合、たとえば以下のようにするなど。
server { listen 80 default_server; root /var/www; index index.html index.htm; location / { try_files $uri $uri/ =404; } # fast cgi support include /etc/nginx/fcgiwrap.conf; } server { listen 80; server_name hogehoge.piano.or.jp; location / { root /var/www/hogehoge; index index.html index.htm; try_files $uri $uri/ =404; } # fast cgi support include /etc/nginx/fcgiwrap.conf; } server { listen 80; server_name foobar.piano.or.jp; location / { root /var/www/foobar; index index.html index.htm; try_files $uri $uri/ =404; } # fast cgi support include /etc/nginx/fcgiwrap.conf; }
言うまでもなく、SSLの場合は443についての記述も入れつつ。
ちなみに、MT6のブログ設定において、サブドメインを利用する、というやり方も
とれなくはないのですが、個人的には、nginxのconfに設定をまとめておいた方が、
後々のメンテナンス性が高くなって幸せ感が高まるんじゃないかと思います。
perlのインストール
aptitude -y install perl
nginxの場合、apacheよりcgi動かすまでの道のりが長くて大変なのですが。
まあ、サクサクといきましょう。
fcgiwrapのインストール
apt-get install fcgiwrap
cp /usr/share/doc/fcgiwrap/examples/nginx.conf /etc/nginx/fcgiwrap.conf
/etc/nginx/sites-available/default に、以下を追記してー、
# fast cgi support include /etc/nginx/fcgiwrap.conf;
/etc/nginx/fcgiwrap.conf の中身を以下に書き換え、
location ~ \.cgi(/|$) { gzip off; fastcgi_index index.cgi; fastcgi_split_path_info ^(.+?\.cgi)(/.*)$; if (!-e $document_root$fastcgi_script_name) { return 404; } fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $fastcgi_path_info; fastcgi_pass unix:/var/run/fcgiwrap.socket; }
fcgiwrapの起動(nginxの再起動もやっておいた方が吉かもです)
/etc/init.d/fcgiwrap start
なお、fcgiwrap再起動の時は restart 、停止の時は stop で。
MT + fcgiwrapの環境って、ストレートにやっても動いてくれませんで、403forbidden
無間地獄に堕とされますから、fcgiwrap.confの中身を上のように書き換えないとならず。
このあたりについては、公式様と以下記事を参照に。
FCGI Wrap
https://www.nginx.com/resources/wiki/start/topics/examples/fcgiwrap/
Movable Type DataAPIをDebian Wheezyで動かす(nginx + fcgiwrap) - uehatsu's tech blog
https://uehatsu.info/tech/archives/2015/11/run-movable-type-dataapi-on-debian-wheezy-with-nginx-and-fcgiwrap.html
PSGIの方が動かしやすそうかもしれませんが、何となくそれほどの根拠もなくfcgiwrapの方が
イイ感じのような……(根拠ある情報があるようでしたら欲しいです)
MySQLのインストール
apt-get install mysql-server
MySQLをインストールするとlatin1になってしまっているので、UTF8にしなくてはならない
のですが、そのあたりの日本語化とか他詳細は、以下参照。
Ubuntu で MySQL
http://qiita.com/kojionilk/items/bdace886c3664d75c5f7
MySQLの設定
MTデータベース作成。
create database mt character set utf8; grant all on mt.* to hogehogeuser@localhost identified by 'foobarpassword';
MTの設定
http://hogehoge/mt/ にアクセスして、サインインボタンからおこなう。
あとは、ブラウザ上で順々に入力していけば、めでたくMT管理画面に到着します。
apacheより高速サクサクな再構築が楽しめます。