linux yum 安装smarty,在CentOS上成功安装Smarty

c4468b3f4df77e96b0a416fa2a870fba.png

根据Smarty的文档说明安装了Smarty,结果测试不成功,后来发现是templates_c目录权限设置不当(要设置成777)。现根据其QUICK_START文件,把整个安装过程描述如下,以作备查。

1、下载最新Smarty软件,比如最新Smarty-2.6.20.tar.gz下载到test用户根目录下

http://www.smarty.net/

2、解压并拷贝libs目录到某个目录下(假设已经在/usr/lib/php/目录下已建smarty目录)

test$ tar zxvf Smarty-2.6.20.tar.gz

test$ cp Smarty-2.6.20/libs/* /usr/lib/php/smarty -r

此时smarty目录结构如下:

/usr/lib/php/smarty/

Config_File.class.php

debug.tpl

internals/

plugins/

Smarty.class.php

Smarty_Compiler.class.php

3、新建WEB目录和相关目录

test$ cd /var/www/html

test$ mkdir smarty

test$ mkdir smarty/templates

test$ mkdir smarty/templates_c

test$ mkdir smarty/cache

test$ mkdir smarty/configs

test$ chmod 777 smarty/templates_c????? //不成功的原因就在此,原为775

test$ chmod 777 smarty/cache????? //设置成与上述相同的权限

4、新建一个PHP文件

test$ cd /var/www/html/smarty

test$ vi index.php   添加如下内容

require('/usr/lib/php/smarty/Smarty.class.php');

$smarty = new Smarty();

$smarty->template_dir = '/var/www/html/smarty/templates';

$smarty->compile_dir = '/var/www/html/smarty/templates_c';

$smarty->cache_dir = '/var/www/html/smarty/cache';

$smarty->config_dir = '/var/www/html/smarty/configs';

$smarty->assign('name', 'Ned');

$smarty->display('index.tpl');

?>

5、新建模板文件

test$ cd /var/www/html/smarty/templates

test$ vi index.tpl????? 添加如下内容

Smarty

Hello, {$name}!

6、测试成功与否

在浏览器中访问http://localhost/index.php,如果成功可以看到“Hello Ned!”。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值