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服务器

相关文章
相关标签/搜索