在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 GUI库图形界面开发之PyQt5中QWebEngineView内嵌网页与Python的数据交互传参详细方法实例2. docker /var/lib/docker/aufs/mnt 目录清理方法3. Vuex localStorage的具体使用4. python+excel接口自动化获取token并作为请求参数进行传参操作5. 《CSS3实战》笔记--渐变设计(三)6. Notepad++如何安装Python插件?Notepad++插件怎么装?7. ASP.NET泛型三之使用协变和逆变实现类型转换8. Python matplotlib画图时图例说明(legend)放到图像外侧详解9. 6个常见的 PHP 安全性攻击实例和阻止方法10. 使用Android studio查看Kotlin的字节码教程

网公网安备