在Ubuntu 14中安装配置smarty
步骤1:在Web服务器(Apache2)根目录下,新建一个站点。如下:
# cd /var/www/html/# mkdir www.mysmarty.com步骤2:到官网下载smarty包,http://www.smarty.net/,这里我下载的是smarty-3.1.30.tar.gz;
步骤3:解压后,将里面的libs目录复制到上面新建的站点中,如下:
# tar -zxvf smarty-3.1.30.tar.gz# cp -rf libs /var/www/html/www.mysmarty.com/步骤4:在站点根目录中新建如下几个目录,并把templates和templates_c的访问权限设为775,如下:
# cd /var/www/html/www.smarty.com/# mkdir cache configs templates templates_c# chmod -R 775 templat*步骤5:在站点根目录中新建一个测试文件index.php和模板index.tpl,并将模板index.tpl放在templates目录中,如下:
# cd /var/www/html/www.smarty.com/# touch index.php# cd templates# touch index.tpl步骤5:index.php代码如下:
<?php require_once('libs/Smarty.class.php'); $smarty = new Smarty(); $smarty->template_dir = 'templates'; $smarty->complie_dir = 'templates_c'; $smarty->config_dir = 'configs'; $smarty->cache_dir = 'cache'; $smarty->assign('name', 'World'); $smarty->display('index.tpl'); ?>步骤6:模板文件index.tpl如下:
{* Template *} Hello, {$name}步骤7:在浏览器中输入http://localhost/www.mysmarty.com/,就会出现Hello,World表示Smarty配置成功!