Zend Framework

概要

Zend Framework は Model-View-Controller (MVC) フレームワークで、1つの配布物の中でほとんどのwebアプリケーションに必要とされる全てのコンポーネントを提供します。既存のPHPスタックに追加、あるいはZend サーバのフリーあるいは有料バージョンに同梱されています。

Zend Frameworkを既にインストールされているPHPスタックに追加するためには、webサイト上のインストレーション手順に下あってください:

Zend Frameworkの最新バージョンをダウンロードし、内容を解凍することができます; どこでそうしたかを覚えておいてください。任意に、書庫のライブラリ/サブディレクトリのパスをphp.iniのinclude_path設定へ追加することができます。以上です!Zend Frameworkはこれでインストールされ使うことができます。

そうしたければ、今読むことを止め、PHP FastCGIを使ってNGINXを直接動作する設定方法を勉強することができます。

もう一つの方法として、Zend Framework は、Zend Serverのフリーおよび有料エディションの両方にもパッケージされています:

Zend Server includes a production-ready, tested stack that incorporates PHP, Zend Framework, required extensions and drivers - all installed through RPM/DEB on Linux or MSI on Windows. Zend Server はIBM iもサポートします。

このガイドの残りで、PHPバージョン 5.3のための Zend Server フリーエディションを使ったNGINXの統合をカバーします。私のインストレーションはUbuntu 10.10 Maverick Meerkat 上ですが、あなたのものでも同様に動作するはずです。全てのサポートされるプラットフォームのための詳細はインストレーションはhttp://files.zend.com/help/Zend-Server-6/zend-server.htm#installation_guide.htmにあります。

考慮すべき点についての私の所見

  • Zend Server 6.1から、NginxはZend Serverによってネイティブにサポートされています。
  • 非NGINXのセットアップでは、Zend Serverは、実際のPHPアプリケーションの提供についてApache2.2、Zend Server Administration GUIについてlighthttpの両方を含みます。
  • Zendからの追加のパッケージおよびファイルの数は幾分多いです; PHP5.3 (5.4もサポートされます)だけでなく、Zend Framework, Apache 2.2 および Zend Server Administration GUI も取得します。
  • また、一旦Zend Serverをインストールすると、ディストリビューションの"native"PHPインストレーションパッケージは今は時代遅れのため、削除されるでしょう。
  • on the upside, Zend provides repositories for Redhat/CentOS as well as Debian/Ubuntu, hence whenever you update your system, the Zend Server packages including your Zend Framework will be updated with your regular update process, e.g. aptitude full-upgrade or yum update. 特にapticronのようなものを使っている場合は、本当に良いです。もう時代遅れのPHPあるいはZend Frameworkライブラリはありません。素晴らしい!
  • PHP 5.3から、spawn-fcgiを使うことはもはやcoolでは無いように思われます(ここのコメントを見てください)。The new cool kid apparently is php-fpm.

Allright, with no further ado, here we go ...

自動化されたインストレーションの指示

Zend Server 6.1から、NGINX & Zend Serverをインストールするために自動化されたインストレーションスクリプトを使うことができます。

  1. zend.comから"Zend Server (DEB/RPM Installer Script)"という名前のパッケージをダウンロードします - http://www.zend.com/en/products/server/downloads

  2. パッケージの場所を見つけ解凍します: ZendServer-X.X.X-RepositioryInstaller-linux.tar.gz

  3. インストーラスクリプトを実行するディレクトリに切り替え:

    cd ZendServer-RepositoryInstaller-linux/
    
  4. 使用しようと思うPHPバージョン(5.3 あるいは 5.4) に応じて、以下のコマンドを実行します:

    ./install_zs.sh <PHP Version> nginx
    

手動インストレーション指示

またですが、私はUbuntu上ですのでhttp://files.zend.com/help/Zend-Server-6/zend-server.htm#deb_installing_zend_server.htmのためのインストレーション指示に従っていました。このことは、/etc/apt/sources.listを更新し、ZendのリポジトリのためのGPGキーをインポートしなければならないことを意味します。ですので指示を注意深く読むようにしてください!

以下のコマンドはZend Server フリーエディションをインストールし、その後でApache 2.2 および Zend Server GUI の両方を停止します。

sudo aptitude update
sudo aptitude install zend-server-php-5.3
sudo service zend-server stop

Once that is done, you want to create a custom php-fastcgi script for Zend Server Free Edition that NGINX can use to forward PHP template processing to, just as you would do for a regular PHP installation.

rootとしてファイル/etc/init.d/php-fastcgi を作成し、以下の内容をその中に配置します:

#!/bin/bash
# Inspired from /usr/local/zend/bin/lighttpdctl.sh
# Zend GUI uses lighttpd and fastcgi - we want the same for NGINX
# its all about the unix socket - if on the same machine
# otherwise bind to address and port; this is similar to the "regular" php-fastcgi

if [ -f /etc/zce.rc ];then
    . /etc/zce.rc
else
    echo "/etc/zce.rc doesn't exist!"
    exit 1;
fi

start()
{
    if !kill -0 `cat $ZCE_PREFIX/tmp/php-fcgi.pid 2>/dev/null` 2>/dev/null;then
        killall -9  $ZCE_PREFIX/gui/lighttpd/sbin/php 2>/dev/null
        rm $ZCE_PREFIX/tmp/php-fcgi.pid 2>/dev/null
    fi
    $ZCE_PREFIX/gui/lighttpd/bin/spawn-fcgi \
      -s $ZCE_PREFIX/tmp/php-fastcgi.socket \
      -f "$ZCE_PREFIX/gui/lighttpd/sbin/php -c $ZCE_PREFIX/etc/php.ini" \
      -u zend -g zend -C 5 -P $ZCE_PREFIX/tmp/php-fcgi.pid
    chmod 666 $ZCE_PREFIX/tmp/php-fastcgi.socket
}
stop()
{
    if !kill -0 `cat $ZCE_PREFIX/tmp/php-fcgi.pid 2>/dev/null` 2>/dev/null;then
        killall -9 $ZCE_PREFIX/gui/lighttpd/sbin/php 2>/dev/null
        rm $ZCE_PREFIX/tmp/php-fastcgi.socket 2>/dev/null
        rm $ZCE_PREFIX/tmp/php-fcgi.pid 2>/dev/null
    else
        kill `cat $ZCE_PREFIX/tmp/php-fcgi.pid 2>/dev/null` 2>/dev/null
    fi

}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                sleep 1
                start
                ;;
        *)
                使い方
                exit 1
esac

exit $?

気づいたように、NGINXの設定に幾らかの影響があるだろう様々な設定を Zend インストレーション (/etc/zce.rc) から取り出しました。特に、私は同じマシーン上でNGINXとZend Server Frameworkの両方を使うため、パフォーマンス上の理由からUnixソケットを使うことを決めました。ファイルの残りはspawn-cgiも使用するビルトインのZend GUI(lighttpdに基づいています)のためのstartおよびstopスクリプトによってインスパイアされています!!

次に、ファイルを実行可能にし、システムデーモンを制御するためにそれをサーバの通常の環境に追加します:

cd /etc/init.d
sudo chmod 644 php-fastcgi
sudo chmod +x php-fastcgi
sudo update-rc.d php-fastcgi defaults

ポートの衝突を避け、システムのリソースを節約するために、そしてもちろんApacheがもう必要ないため、Apache 2.2 と Zend GUI (lighttpd) を自動起動させないようにします。

cd /etc/init.d
sudo update-rc.d -f zend-server remove

NGINXのための時間

これで、残っているのはNGINXを設定して全てのPHPリクエストを新しくインストールされたZend Server に転送する設定することです。PHP FastCGIのための通常の指示を厳しく学ぼうと思います。Unixソケットを使っていて、Zend Server PHP CGIプロセスを TCP/IPポートにバインドしないことだけを忘れないでください。したがって、PHPのための設定はこのようになります。Also note: this is just the part in regards to plain PHP, most likely you would also want to make sure, no requests will be forwarded to Zend Server for any of your static or cached content!!

server {
  listen      80;
  server_name www.example.com;
  root        /var/www/www.example.com/myapplication;
  index       index.html index.htm index.php;

  location / {
    try_files $uri $uri/ /index.php$is_args$args;
  }

  location ~ \.php$ {
    fastcgi_pass   unix:/usr/local/zend/tmp/php-fastcgi.socket;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
  }
}

fastcgi_passfastcgi_param SCRIPT_FILENAME パラメータに特に注意してください; それらは明示的に特定のインストレーション上のディレクトリとファイルを指しています!!!

それはこうでしょう - 試してみてください、幸運を祈ります!!!

TOP
inserted by FC2 system