この記事の所要時間: 約 22分24秒

さくらインターネットのVPS に、申し込みをしてやっと完了メールが来ました。
に、申し込みをしてやっと完了メールが来ました。
4月16日の予定だったのですが、申し込み殺到みたいで
完了連絡が来たのは、4月18日でした。
まあ、申し込んだのが4月12日だったので、1週間程度かなと。
ちなみに、今だと在庫があるみたいなので
すぐに、利用開始じゃないかなぁと。
ここから、申し込みできますよ。
 
さっそく、サーバが来たのでセットアップ作業をしました。
今回は、apache+PHP+MySQLだと面白くないので
nginx+PHP+MySQLの環境に、チャレンジしました!
セットアップしたメモも、残しておきます。
何かの役に立つかな^^
セットアップメモ
環境確認
cat /etc/redhat-release CentOS release 6.2 (Final)
CentOSの6.2が、セットアップされています。
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm rpm -Uvh epel-release-6-5.noarch.rpm
EPEL入ってないと思ったら、実は最初から入ってたw
で、remiも入れておきます。
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
MySQLインストール
ということで、MySQLをインストールyum install mysql mysql-server
yumコマンドで一発インストールです!便利♪
自動起動も設定しておきます。
リブートしたら起動しないと危険なので^^
chkconfig mysqld on chkconfig --list mysqld
MySQLを、起動します。
/etc/init.d/mysqld start
PHPインストール
次に、PHPのインストールyum --enablerepo=remi-test install php php-devel php-mysql php-mbstring php-pear php-mysql
これも、yumコマンドで簡単にインストール!
インストーされたか確認
php -v
無事に、インストールされています。
PHPアクセラレーター設定
つぎは、eAccellaretorもインストールしておきます。wget http://downloads.sourceforge.net/sourceforge/eaccelerator/eaccelerator-0.9.6.1.zip unzip eaccelerator-0.9.6.1.zip
ダウンロードして解凍したら、ビルドしてインストール
cd eaccelerator-0.9.6.1 phpize ./configure --enable-eaccelerator=shared make
エラーが出ました><
う〜ん、PHP5.4だと、eAccellaretor 動かないかも。
ということで、APCにしちゃいます。
make clean
で、とりあえず、makeを削除しておいて。
cd
ディレクトリを戻して
svn co http://svn.php.net/repository/pecl/apc/trunk/ apc-trunk cd apc-trunk /usr/local/php/bin/phpize ./configure --enable-apc --enable-apc-mmap --with-apxs --with-php-config=/usr/bin/php-config make
あれ、エラーがでる><
色々調べると、pcre-develを入れないとダメみたい。
ということで、pcre-develも、インストール
yum install pcre-devel
pcre-develを入れたので再チャレンジ!
./configure --enable-apc --enable-apc-mmap --with-apxs --with-php-config=/usr/bin/php-config make
通った!
make test make install
おっ、行けそう! php.iniを変更します。
vi /etc/php.ini
extension="apc.so"
を追加します。
apcが動いているか確認してみます。
apacheを一時的に動かしてみて、phpinfoで確認してみます。
/etc/init.d/httpd restart vi /var/www/phpinfo.php
<?php phpinfo() ?>phpinfo用に、この一行だけ書いて
ブラウザから見てみると。。。
何とか動いてそうです^^
apacheは必要ないので、止めておきます。
/etc/init.d/httpd stop
nginxインストール
今回は、apacheじゃなくて、nginxで動かしたいので
nginxをセットアップ!
まず、ビルドに必要なパッケージを入れます。
yum --enablerepo=epel install make automake gcc gcc-c++ rpm-build spawn-fcgi \ pcre-devel zlib-devel openssl-devel libxslt-devel GeoIP-devel gd-devel
で、nginxをインストールします。
キャッシュを効かせないんだったら、パッケージでも良かったんだけど
実は、ソースでやらないと、キャッシュが効かないので、1回入れ直しになりました><
nginxパッケージ インストール方法
(キャッシュ効かないけど一応残しておきます。)
パッケージ
wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
wget http://dl.fedoraproject.org/pub/epel/6/SRPMS/nginx-1.0.14-1.el6.src.rpm sudo rpm -ivh nginx-1.0.14-1.el6.src.rpm
ソースを落として、インストール
ディレクトリを作成
mkdir /usr/src/redhat mkdir /usr/src/redhat/SOURCES mkdir /usr/src/redhat/SPECS mkdir /usr/src/redhat/RPM
nginxをインストール
rpm -ivh nginx-1.0.14-1.el6.src.rpm
警告が出るけど、ユーザーがないだけだから大丈夫。
警告: グループ mockbuild は存在しません - root を使用します 警告: ユーザ mockbuild は存在しません - root を使用します 警告: グループ mockbuild は存在しません - root を使用します
最新のnginxソースコードをダウンロード
cd rpmbuild/SOURCES wget http://nginx.org/download/nginx-1.1.9.tar.gz
nginx.spec の設定
cd ../SPECS cp nginx.spec nginx.spec.org vi nginx.spec
nginx.specのVersion情報を書き換え
Name:              nginx
#Version:           1.0.14
Version:           1.1.9
Release:           1%{?dist}言語と文字コードも追加しておきます。
# variable.
export LANG='ja_JP.UTF-8'
export DESTDIR=%{buildroot}rpm作成
rpmbuild -bb nginx.spec
ソースコードのダウンロードをします。
cd /usr/src/redhat/SOURCES wget http://nginx.org/download/nginx-1.1.9.tar.gz tar xvzf nginx-1.1.9.tar.gz
レポジトリファイルを作成します。
vi /etc/yum.repos.d/nginx.repo
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
この内容を書き込みます。
リポジトリ動作確認をしてみます。
yum list nginx
nginxをインストールします。
yum install nginx
PHP FastCGI設定
PHPが、nginxで動かないので
nginx と PHP FastCGI の設定を行います。
素敵なことに、FastCGIファイルが用意されているので
そこから、ダウンロード♪
wget http://sakuratan.biz/nginx/php-fastcgi mv php-fastcgi /etc/init.d chmod 755 /etc/init.d/php-fastcgi
pidファイル用のディレクトリ作成
mkdir /var/run/nginx chown nginx:nginx /var/run/nginx
php-fastcgiを起動してみます。
/etc/init.d/php-fastcgi start
Cache Purge plugin をインストールします。
wget http://labs.frickle.com/files/ngx_cache_purge-1.3.tar.gz
nginx.conf を設定
サイトのサンプルを利用しました!
user              nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;
 
pid        /var/run/nginx.pid;
 
events {
    worker_connections  1024;
}
 
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
 
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
    access_log  /var/log/nginx/access.log  main;
 
    sendfile        on;
 
    keepalive_timeout  5;
 
    gzip  on;
    gzip_disable "MSIE [1-6]\.";
 
    proxy_cache_path  /var/cache/nginx levels=1:2 keys_zone=czone:4m max_size=50m inactive=120m;
    proxy_temp_path   /var/tmp/nginx;
    proxy_cache_key   "$scheme://$host$request_uri";
    proxy_set_header  Host               $host;
    proxy_set_header  X-Real-IP          $remote_addr;
    proxy_set_header  X-Forwarded-Host   $host;
    proxy_set_header  X-Forwarded-Server $host;
    proxy_set_header  X-Forwarded-For    $proxy_add_x_forwarded_for;
 
    upstream backend {
        ip_hash;
        server 127.0.0.1:8080;
    }
 
    server {
        listen       80;
        server_name  example.com;
 
        location / {
            if ($http_user_agent ~* '(DoCoMo|J-PHONE|Vodafone|MOT-|UP\.Browser|DDIPOCKET|ASTEL|PDXGW|Palmscape|Xiino|sharp pda browser|Windows CE|L-mode|WILLCOM|SoftBank|Semulator|Vemulator|J-EMULATOR|emobile|mixi-mobile-converter)') {
                set $mobile 1;
            }
            if ($http_user_agent ~* '(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry)') {
                set $mobile 2;
            }
            if ($http_cookie ~* "comment_author_[^=]*=([^%]+)%7C|wordpress_logged_in_[^=]*=([^%]+)%7C") {
                set $do_not_cache 1;
            }
            proxy_no_cache     $do_not_cache;
            proxy_cache_bypass $do_not_cache;
            proxy_cache czone;
            proxy_cache_key "$scheme://$host$request_uri$is_args$args$mobile";
            proxy_cache_valid  200 301 302 10m;
            proxy_cache_valid  404 5m;
            proxy_cache_use_stale  error timeout invalid_header updating
                                   http_500 http_502 http_503 http_504;
            proxy_pass http://backend;
            proxy_redirect http://example.com:8080/ /;
        }
 
        location ~ /purge(/.*) {
            allow 127.0.0.1;
            allow 192.0.2.1;
            deny all;
            proxy_cache_purge czone "$scheme://$host$1$is_args$args$mobile";
        }
    }
 
    server {
        listen       8080;
        server_name  example.com;
 
        location / {
            root   /var/www/html;
            index  index.html index.htm index.php;
        }
 
        error_page  404              /404.html;
        location = /404.html {
            root   /usr/share/nginx/html;
        }
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
 
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
            include        fastcgi_params;
        }
 
        location ~ /\.ht {
            deny  all;
        }
    }
 
    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;
}下記の設定箇所を、自分の環境用に書き変えて
nginx.confを書き換えます。
サーバの IP アドレス: 192.0.2.1 ホスト名: example.com HTML ドキュメントルート: /var/www/html リバースプロクシのポート: 80 バックエンドウェブサーバのポート: 8080 PHP FastCGI サーバのポート: 9000
書き換える前に、一応バックアップを取っておいて。
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.org
nginx.confを、書き換えます。
vi /etc/nginx/nginx.conf
nginxを起動!
/etc/init.d/nginx start
結局、キャッシュが効きません><
よく調べてみると、nginxとngx_cache_purgeを設定して
再コンパイルしないと、いけないらしい
ということで、nginxとキャッシュ用のプラグインを入れ直します。
nginx と ngx_cache_purge設定
perl-ExtUtils-Embedインストール
後で気がついたんですが、perl-ExtUtils-Embedはコンパイルに必要なので事前に入れておきます。
cd yum install perl-ExtUtils-Embed
yumで入れられるから、楽ちんです。
ディレクトリを移動して、モジュールをダウンロード
cd wget http://dl.fedoraproject.org/pub/epel/6/SRPMS/nginx-1.0.14-1.el6.src.rpm sudo rpm -ivh nginx-1.0.14-1.el6.src.rpm
展開すると、rpmbuild ってディレクトリが出来て
ソースが配置されます。
で、今回は、nginx と ngx_cache_purgeを最新版にしたいので
それぞれの、最新モジュールを準備しておきます。
cd rpmbuild/SOURCES wget http://nginx.org/download/nginx-1.1.9.tar.gz wget http://labs.frickle.com/files/ngx_cache_purge-1.5.tar.gz
nginx.spec ファイルを書き換えます。
cd ../SPECS cp nginx.spec nginx.spec.org vi nginx.spec
nginx.specのVersion情報を書き換え
Name:              nginx
#Version:           1.0.14
Version:           1.1.9
Release:           1%{?dist}言語と文字コードも追加しておきます。
# variable.
export LANG='ja_JP.UTF-8'
export DESTDIR=%{buildroot}で、コンパイルし直し
cd ../SPECS/ sudo rpmbuild -bb nginx.spec
伸張ファイルの検査中: /usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/nginx-1.1.9-1.el6.x86_64 書き込み完了: /root/rpmbuild/RPMS/x86_64/nginx-1.1.9-1.el6.x86_64.rpm 書き込み完了: /root/rpmbuild/RPMS/x86_64/nginx-debuginfo-1.1.9-1.el6.x86_64.rpm 実行中(%clean): /bin/sh -e /var/tmp/rpm-tmp.XQYgk1 + umask 022 + cd /root/rpmbuild/BUILD + cd nginx-1.1.9 + rm -rf /root/rpmbuild/BUILDROOT/nginx-1.1.9-1.el6.x86_64 + exit 0
無事コンパイル出来ました!
rpmでインストールすれば、OK。
sudo rpm -Uvh nginx-1.1.9-1.el6.x86_64.rpm
前に失敗したけど、nginx.confは、そのまま使えるので
これで、nginxは、無事に動かせました!
nginxを起動!
/etc/init.d/nginx start
ちなみに、セッションディレクトリに権限も設定しておく必要があります。
セッションディレクトリへ権限
chown -R nginx.nginx /var/lib/php/session/ chmod 777 /var/lib/php/session/
ということで、色々苦労しましたが、
何とか、nginxが動きました。
前のwordpressの環境の引っ越しが残ってますが
とりあえず、今回はここまで。
次回はWordpressの引っ越し編の予定です^^
さくらのVPS便利ですね〜♪
 
参考サイト
CentOSでnginxリバースプロクシとWordpressのブログを立ち上げる手順http://d.hatena.ne.jp/paraches/20120213
apache のかわりにnginxを使ってみる(1)-3 リバースプロキシのキャッシュ削除モジュール nginx cache purge を組み込む
http://sakura.off-soft.net/cen……stall.html
さくらVPSとnginxリバースプロクシで最速WordPressブログを作る方法(ベンチマーク付き) | さくらたんどっとびーず
http://snip-snap.posterous.com……xwordpress
WordPress on PHP5.4.0 RC4 + APC
http://dogmap.jp/2012/01/03/wo……4rc04-apc/
APCインストール参考
Installing APC from beta/alpha development onto centOS 5.4 64 bit dual core
http://palma-seo.com/content/i……5-4-64-bit
 
							






[...] 前回記事:さくらVPSに申し込んだよ。nginx / wordpressセットアップまとめ http://blog.bot.vc/2012/05/sakuravps/ まずは、データの移行です。 wordpressのデータの移行方法は [...]
[...] 今回はさくらVPSに申し込んだよ。nginx / wordpressセットアップまとめの記事を参考に(コピペ)作業しました。 [...]
[...] 今回はさくらVPSに申し込んだよ。nginx / wordpressセットアップまとめの記事を参考に(コピペ)作業しました。 [...]
[...] 今回はさくらVPSに申し込んだよ。nginx / wordpressセットアップまとめの記事を参考に(コピペ)作業しました。 [...]