当サイトをご利用頂き有難うございます。
当サイトは今月末日にモールタイプの総合検索サイトへリニューアルの予定です。
サイト名も変更となりますが、今後とも宜しくお願いいたします。

php+php_Smarty

アプリケーションの稼動に必要なソフトの中から、今回は php5 をインストールします。
現在、バージョンは5.2.6です。5.2.7にはセキュリティに脆弱性が発見され見送りです。
また、テンプレートエンジンにphp-Smartyを使用します。

①phpのインストール

 GNOME端末より

   # su + 管理者権限パスワード

   # yum install php  を入力

   # y

    完了です。

②php-pear(PHPの拡張ライブラリ)のインストール

   # yum install php-pear  を入力

   # y

    完了です。

③php-mbstring(日本語の処理)のインストール

   # yum install php-mbstring  を入力

   # y

    完了です。

④php-mysql(PHPからはMySQLに接続するのに必要)のインストール

   # yum install php-mysql  を入力

   # y

   # exit

    完了です。

⑤php-Smarty(テンプレートエンジン)のインストール

   # yum install php-Smarty  を入力

   # y

   # exit

    完了です。

⑥php.iniの編集(日本語が使えるようにします)

 GNOME端末より

   # su -   + 管理者権限パスワード

   # gedit /etc/php.ini  を入力

;;;;;;;;;;;;;;;;;;;;
; Language Options ;
;;;;;;;;;;;;;;;;;;;;

;allow_call_time_pass_reference = Off
allow_call_time_pass_reference = On   →  関数の引数としてリファレンスを使用

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Log errors to specified file.
;error_log = filename
error_log = "/var/log/php_error"   →  追加

;;;;;;;;;;;;;;;;;
; Data Handling ;
;;;;;;;;;;;;;;;;;

;register_argc_argv = Off
register_argc_argv = On   →  修正

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
include_path = ".:/usr/share/pear:/usr/share/php/Smarty"   →  追加

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Maximum allowed size for uploaded files.
; upload_max_filesize = 2M         →  コメントアウト
multibyte/upload_max_filesize = 30M   →  リストアで利用できるバックアップデータの最大サイズ

( 中略 )

output_buffering = On   →  HTTP BODYを出力した後でもHTTPヘッダが出力できます。
output_handler = mb_output_handler   →  PHPからの標準出力を指定の関数にリダイレクト 
default_charset = Shift_JIS

;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;

( 中略 )

[mbstring]------- コメント(;)の削除 & 設定変更(環境に合わせ変更します) -------
                  
 mbstring.language = Japanese
 mbstring.internal_encoding = UTF-8
 mbstring.http_input = auto
 mbstring.http_output = UTF-8
 mbstring.encoding_translation = On
 mbstring.detect_order = auto

     * この設定は上手く環境に合わせ構築しておかないと、後々に使用する、
       phpMyAdmin等での文字化けに悩む事になります。
        php関連の文字化けが発生したら、真っ先にココの設定を調整してみましょう。

⑦Smarty 用のディレクトリを作成

 GNOME端末より

   # su   + 管理者権限パスワード

   # mkdir -p /var/www/html/smarty   →  環境に合わせ変更(プログラム毎に配置します)
   # cd /var/www/html/smarty
   # mkdir templates templates_c configs cache   →  Smarty 用に4つのディレクトリを作成

⑧Smarty.class.phpを配置

   Smarty : Template Engine の

   Smarty : Downloads より 
    ダウンロードし解凍したファイルから Smarty.class.php を取り出して

    /var/www/html/smarty/Smarty.class.php として配置

⑨フォルダのパーミッションを変更(書き込みが出来るようにします)

 GNOME端末より

   # chmod 777 /var/www/html/smarty/templates_c  を入力

   # chmod 777 /var/www/html/smarty/cache  を入力

⑩Smarty_App クラスファイルを作成

    /var/www/html/smarty/Smarty_App.php として保存

    ----------- Smarty_App.php -----------
    <?php
    require_once 'Smarty.class.php';

    class Smarty_App extends Smarty {
     private $smartyAppBase = '/var/www/html/smarty';
     public function __construct() {
     parent :: __construct();

     $this->template_dir = $this->smartyAppBase.'/templates/';
     $this->compile_dir = $this->smartyAppBase.'/templates_c/';
     $this->config_dir = $this->smartyAppBase.'/configs/';
     $this->cache_dir = $this->smartyAppBase.'/cache/';

     $this->caching = true;
     }
    }
    ?>
    --------------------------------- 以上 ----

⑪Smarty テスト用の php ファイルを作成

    /var/www/html/test_smarty.php として保存

    ----------- test_smarty.php -----------
    <?php
    require_once '/var/www/html/smarty/Smarty_App.php';

    $smarty = new Smarty_App;
    $smarty->assign('var1', 'test_smarty.php');
    $inc_path = ini_get('include_path');
    $smarty->assign('var2', $inc_path);
    $smarty->display('test_smarty.tpl')
    ?>
    --------------------------------- 以上 ----

⑫Smarty テンプレートファイルを作成

    /var/www/html/smarty/templates/test_smarty.tpl として保存

    ----------- test_smarty.tpl -----------
    <HTML>
     <HEAD>
     <META http-equiv=Content-Type content="text/html; charset=utf-8">
     <TITLE>test_smarty.tpl</TITLE>
     </HEAD>
     <BODY>
     file name = {$var1}<BR/>
     php include_path = {$var2}<BR/>
     SMARTY_DIR = {$smarty.const.SMARTY_DIR}<BR/>
     </BODY>
    </HTML>
    --------------------------------- 以上 ----


⑬smarty ディレクトリの所有権の変更

 GNOME端末より

   # su   + 管理者権限パスワード

   # chown -R apache:apache /var/www/html/smarty

    * 既定(httpd.conf)で apache:apache が設定されているので、必要に応じて変更

⑭httpd(Apache)を再起動

  GNOME端末より

   # service httpd restart を入力

⑮確認

  ブラウザで Smarty テスト用の php ファイル(test_smarty.php)にアクセス


インストール終了です。
php関連のエンジンの開発者さまに感謝感謝です。appli01