2010/05/13  |  Written by  |  under Blog

以前の記事はDebianだったのですが、それをCentOSに設定したので、そのメモ。

ここを参考に、FastCGI用daemonのスクリプトを作成。

1
% sudo vim /etc/init.d/php-fastcgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh
#
# php-cgi - php-fastcgi swaping via  spawn-fcgi
#
# chkconfig:   - 85 15
# description:  Run php-cgi as app server
# processname: php-cgi
# config:      /etc/sysconfig/phpfastcgi (defaults RH style)
# pidfile:     /var/run/php_cgi.pid
# Note: See how to use this script :
# http://www.cyberciti.biz/faq/rhel-fedora-install-configure-nginx-php5/
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
spawnfcgi="/usr/bin/spawn-fcgi"
php_cgi="/usr/bin/php-cgi"
prog=$(basename $php_cgi)
server_ip=127.0.0.1
server_port=9000
server_user=nginx
server_group=nginx
server_childs=5
pidfile="/var/run/php_cgi.pid"
 
# do not edit, put changes in /etc/sysconfig/phpfastcgi
[ -f /etc/sysconfig/phpfastcgi ] && . /etc/sysconfig/phpfastcgi
 
start() {
    [ -x $php_cgi ] || exit 1
    [ -x $spawnfcgi ] || exit 2
    echo -n $"Starting $prog: "
    daemon $spawnfcgi -a ${server_ip} -p ${server_port} -u ${server_user} -g ${server_group} -P ${pidfile} -C ${server_childs} -f ${php_cgi}
    retval=$?
    echo
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile} $prog -QUIT
    retval=$?
    echo
    [ -f ${pidfile} ] && /bin/rm -f ${pidfile}
    return $retval
}
 
restart(){
    stop
    sleep 2
    start
}
 
rh_status(){
    status -p ${pidfile} $prog
}
 
case "$1" in
    start)
        start;;
    stop)
        stop;;
    restart)
        restart;;
    status)
        rh_status;;
    *)
        echo $"Usage: $0 {start|stop|restart|status}"
        exit 3
esac

今回はspawn-fcgiを使うので、そのパッケージもインストールします。そして実行権限をつけて、自動起動するように設定。

1
2
3
4
% sudo yum install spawn-fcgi
% sudo chmod a+x /etc/init.d/php-fastcgi
% sudo /sbin/chkconfig --add php-fastcgi
% sudo /sbin/chkconfig php-fastcgi on

次にnginxの設定。CentOSではDebianのように個別の設定に分かれていないので、/etc/nginx/nginx.confを直接編集します。今回は変更した部分のみ掲載します。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    server {
        listen       80;
        server_name  stnard.jp;

        access_log  /var/log/nginx/stnard.jp.access.log  main;

        location / {
            root   /var/www/html;
            index  index.php index.html index.htm;

            # static files
            if (-f $request_filename) {
                expires 30d;
                break;
            }

            # request to index.php
            if (!-e $request_filename) {
                rewrite ^(.+)$  /index.php?q=$1 last;
            }
        }

        # 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  /var/www/html/$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny  all;
        }
    }

作成したら構文チェックして再起動します。ついでにFastCGIの方も起動しておきます。

1
2
3
% sudo /sbin/service nginx configtest
% sudo /sbin/service nginx restart
% sudo /sbin/service php-fastcgi start

とこんな感じで、Debianと同じような環境ができあがりました。

 
このエントリーを含むはてなブックマークはてなブックマーク - WordPress on nginx with FastCGIのCentOSの場合 この記事をクリップ!Livedoorクリップ - WordPress on nginx with FastCGIのCentOSの場合 Googleブックマークに追加 Digg This
Tags: , , ,

Standardプランの契約ができたので、早速設定。

  • /etc/ssh/sshd_config
    1
    2
    3
    Port xxxxx # ポート番号変更
    PasswordAuthentication no # パスワードログインの禁止
    PermitRootLogin no # rootログインの禁止
  • 必要なパッケージの導入
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    $ sudo su -
    # yum update
    # yum install zsh lv
    # chsh -s /bin/zsh
    # useradd hoge
    # passwd hoge
    # su - hoge
    $ chsh -s /bin/zsh
    $ exit
    # visudo
  • 公開鍵の登録とsshサーバの再起動、確認
  • パッケージのインストールと設定
    1
    2
    % sudo yum install mysql-server php-mysql
    % sudo vim /etc/httpd/conf/httpd.conf
  • iptablesの設定
  • PHPのインストール
    1
    2
    3
    4
    $ sudo yum install php-pear-Net-Socket php-pear php-common php-gd php-devel php php-mbstring php-pear-Mail php-cli php-imap php-snmp php-pdo php-xml php-pear-Auth-SASL php-ldap php-pear-Net-SMTP php-mysql
    $ sudo vim /var/www/html/index.php
    $ sudo /sbin/service httpd restart
    $ sudo rm /var/www/html/index.php
  • nginxのインストール
    1
    2
    3
    4
    5
    $ sudo /sbin/service httpd stop
    $ sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-3.noarch.rpm
    $ sudo yum install nginx
    $ sudo chkconfig httpd off
    $ sudo chkconfig nginx on

と、ここまで設定して面倒になったので続きは後日。

 
このエントリーを含むはてなブックマークはてなブックマーク - DTIのServersMan@VPS Standardプランで最初にやったこと この記事をクリップ!Livedoorクリップ - DTIのServersMan@VPS Standardプランで最初にやったこと Googleブックマークに追加 Digg This
Tags: , ,