您的位置:首页技术文章
文章详情页

在CentOS上成功安装Smarty

【字号: 日期:2024-07-10 10:43:39浏览:6作者:猪猪

根据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.phpdebug.tplinternals/plugins/Smarty.class.phpSmarty_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 添加如下内容

<?php// put full path to Smarty.class.phprequire(’/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 添加如下内容

<html><head><title>Smarty</title></head><body>Hello, {$name}!</body></html>

6、测试成功与否

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

标签: CentOS
相关文章: