Nginx.PHP配置Smarty

來源:互聯網
上載者:User

標籤:style   blog   http   ar   color   使用   sp   檔案   on   

  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基本配置資訊),內容如下
    <?phpdefine(‘SMARTY_DIR‘,‘/usr/local/lib/smartyLibs/‘);//定義lib路徑require_once(SMARTY_DIR.‘Smarty.class.php‘);//引用Smarty庫$smarty=new Smarty();//建立Smarty$smarty->setTemplateDir(‘./templates‘);$smarty->setCompileDir(‘./templates_c‘);$smarty->setConfigDir(‘./configs‘);$smarty->setCacheDir(‘./cache‘);$smarty->caching=false;//是否使用緩衝//$smarty->testInstall();//調試用,顯示4個目錄可讀寫狀態?>

     

  5. 建立網站分頁檔 index.php
    <?phpinclude(‘./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.ini檔案,將 display_error = off 改為 on

重啟php服務

service php-fpm restart

Nginx.PHP配置Smarty

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.