在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.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!”。
相关文章:
1. 如何理解Python中包的引入2. Django中的DateTimeField和DateField实现3. 使用JSP实现简单的用户登录注册页面示例代码解析4. java操作mongodb之多表联查的实现($lookup)5. Python语言规范之Pylint的详细用法6. 深入分析PHP设计模式7. ASP中RecordSet Open和Connection.Execute一些区别与细节分享8. SpringBoot 开发提速神器 Lombok+MybatisPlus+SwaggerUI9. Android View实现圆形进度条10. Python 使用 PyQt5 开发的关机小工具分享