Nginx.PHP配置Smarty

  1. 下載http://smarty.net;
  2. 解壓 -> 將 libs 文件夾重命名 smartyLibs -> 放置在本身服務器的 usr/local/lib/ 中 (/usr/local/lib/smartyLibs);
  3. 在網站目錄,如 site_A 中 建立 4 個必須文件夾 templates、templates_c、configs、cache
    //設置權限
    chown nginx:nginx "4個目錄";
    chmod 770 "4個目錄";
  4. 在網站目錄中建立 smarty.ini.php 配置文件(smarty基本配置信息),內容以下
    <?php
    define('SMARTY_DIR','/usr/local/lib/smartyLibs/');//定義lib路徑
    require_once(SMARTY_DIR.'Smarty.class.php');//引用Smarty庫
    $smarty=new Smarty();//建立Smarty
    
    define('SMARTY_SITE','/var/www/html/site_A/');//定義網站路徑
    $smarty->setTemplateDir(SMARTY_SITE.'templates');
    $smarty->setCompileDir(SMARTY_SITE.'templates_c');
    $smarty->setConfigDir(SMARTY_SITE.'configs');
    $smarty->setCacheDir(SMARTY_SITE.'cache');
    $smarty->left_delimiter='{{';
    $smarty->right_delimiter='}}';
    
    $smarty->caching=false;//是否使用緩存
    
    //$smarty->testInstall();//調試用,顯示4個目錄可讀寫狀態
    ?>

     

  5. 建立網站頁面文件 index.php
    <?php
    include('./smarty.ini.php');//引用smarty.ini.php配置文件
    $name='YangGe123';//自定義變量
    $smarty->assign('name',$name);//將變量賦予smarty值'name'
    $smarty->display('index.tpl');//在templates中引用對應的模板
    ?>

     

  6. 在Templates中建立網站對應的模板
    <html>
        <head></head>
        <body>
            <h1>{$name}</h1>
        </body>
    </html>

     

擴展知識:php

調試php,讓服務器顯示php錯誤信息:html

修改php.ini文件,將 display_error = off 改成 onnginx

重啓php服務緩存

service php-fpm restart服務器

相關文章
相關標籤/搜索