GNU/Linux >> Linux の 問題 >  >> Cent OS

CentOS6にPHP-FastCGIを使用してNginxをインストールする方法

このチュートリアルでは、CentOS 6にPHP-FastCGIを使用してNginxをインストールする方法を示します。知らなかった人のために、Nginxはで最も人気のあるWebサーバーの1つです。世界で最大かつ最もトラフィックの多いサイトのいくつかをホストする責任があります。ほとんどの場合、Apacheよりもリソースに優しく、Webサーバーまたはリバースプロキシとして使用できます。

この記事は、少なくともLinuxの基本的な知識があり、シェルの使用方法を知っていること、そして最も重要なこととして、独自のVPSでサイトをホストしていることを前提としています。インストールは非常に簡単です。 CentOS6サーバーにfast-CGIを使用してNginxを段階的にインストールする方法を説明します。

CentOS6にPHP-FastCGIを使用してNginxをインストールする

ステップ1.インストールするには、まず、CentOS/RHELバージョンに対応するEPELyumリポジトリ情報を追加する必要があります。

## RHEL/CentOS 6 32-Bit ##
# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
## RHEL/CentOS 6 64-Bit ##
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm

ステップ2.Nginxパッケージと依存関係をインストールします。

次のコマンドを使用してNginxをインストールします:

yum update
yum -y install nginx

ステップ3.必要なPHPパッケージをインストールします。

yum install php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

ステップ4.spawn-fcgiをインストールします。

次に、spawn-fcgiをインストールします。 以下のコマンドを使用します:

yum install spawn-fcgi -y

Fast-CGI初期化スクリプトを構成します:

nano /etc/init.d/php-cgi
#!/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
. /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
chmod +x /etc/init.d/php-cgi

ステップ5.NginxWebサーバーを構成します。

#nano /etc/nginx/conf.d/idroot.us.conf

server {
   listen  80;
   server_name  idroot.us www.idroot.us;
 
   access_log  /var/www/idroot.us/logs/access.log ;
   error_log    /var/www/idroot.us/logs/error.log ;
 
   location / {
       root   /var/www/idroot.us/public_html;
       index  index.php index.html index.htm;
 
   }
 
   error_page   500 502 503 504  /50x.html;
   location = /50x.html {
       root   /var/www/idroot.us/public_html;
   }
 
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  location ~ .php$ {
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_index  index.php;
  root    /var/www/idroot.us/public_html;
  fastcgi_param  SCRIPT_FILENAME  /var/www/idroot.us/public_html$fastcgi_script_name;
  include fastcgi_params;
  }

   location ~ /.ht {
       deny  all;
   }
}

ステップ5.NginxおよびPHP-FastCGIサービスを開始します。

etc/init.d/nginx start
etc/init.d/php-cgi start

重要 :セキュリティ上の理由から、次の行を/etc/php.iniに変更/追加して、Nginxを再起動することをお勧めします:

cgi.fix_pathinfo=0

おめでとうございます!NginxとPHP-FastCGIが正常にインストールされました。CentOS6システムにNginxとPHP-FastCGIをインストールするためにこのチュートリアルを使用していただき、ありがとうございます。追加のヘルプや役立つ情報については、以下を確認することをお勧めします。 Nginxの公式ウェブサイト。


Cent OS
  1. CentOS7にngx_pagespeedを使用してNginxをインストールします

  2. CentOS 7 /RHEL7にNginxを使用してphpMyAdminをインストールする方法

  3. CentOS7にSitemagicCMSをインストールする方法–Nginxを使用

  1. CentOS7にNginxをインストールする方法

  2. CentOS7にNginxを使用してWordPressをインストールする方法

  3. CentOS7にNginxを使用してphpMyAdminをインストールする方法

  1. CentOS8にNginxをインストールする方法

  2. CentOS7にMagento2.1をインストールする方法

  3. CentOS7にNginxを使用してSuiteCRMをインストールする方法