Tweet以前の記事は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と同じような環境ができあがりました。
Tags: CentOS, Linux, nginx, WordPress


