在CentOS上成功安装Smarty

2014-11-07 0 713
在CentOS上成功安装Smarty

根据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   添加如下内容

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

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

6、测试成功与否

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

遇见资源网 PHP 在CentOS上成功安装Smarty http://www.ox520.com/21915.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务