在CentOS上成功安裝Smarty
根據(jù)Smarty的文檔說(shuō)明安裝了Smarty,結(jié)果測(cè)試不成功,后來(lái)發(fā)現(xiàn)是templates_c目錄權(quán)限設(shè)置不當(dāng)(要設(shè)置成777)。現(xiàn)根據(jù)其QUICK_START文件,把整個(gè)安裝過(guò)程描述如下,以作備查。
1、下載最新Smarty軟件,比如最新Smarty-2.6.20.tar.gz下載到test用戶根目錄下
http://www.smarty.net/
2、解壓并拷貝libs目錄到某個(gè)目錄下(假設(shè)已經(jīng)在/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
此時(shí)smarty目錄結(jié)構(gòu)如下:
/usr/lib/php/smarty/Config_File.class.phpdebug.tplinternals/plugins/Smarty.class.phpSmarty_Compiler.class.php
3、新建WEB目錄和相關(guān)目錄
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 //設(shè)置成與上述相同的權(quán)限
4、新建一個(gè)PHP文件
test$ cd /var/www/html/smarty
test$ vi index.php 添加如下內(nèi)容
<?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 添加如下內(nèi)容
<html><head><title>Smarty</title></head><body>Hello, {$name}!</body></html>
6、測(cè)試成功與否
在瀏覽器中訪問(wèn)http://localhost/index.php,如果成功可以看到“Hello Ned!”。
相關(guān)文章:
1. React+umi+typeScript創(chuàng)建項(xiàng)目的過(guò)程2. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執(zhí)行過(guò)程解析3. SharePoint Server 2019新特性介紹4. ASP中常用的22個(gè)FSO文件操作函數(shù)整理5. 三個(gè)不常見(jiàn)的 HTML5 實(shí)用新特性簡(jiǎn)介6. ASP調(diào)用WebService轉(zhuǎn)化成JSON數(shù)據(jù),附j(luò)son.min.asp7. .Net core 的熱插拔機(jī)制的深入探索及卸載問(wèn)題求救指南8. 無(wú)線標(biāo)記語(yǔ)言(WML)基礎(chǔ)之WMLScript 基礎(chǔ)第1/2頁(yè)9. 讀大數(shù)據(jù)量的XML文件的讀取問(wèn)題10. 解決ASP中http狀態(tài)跳轉(zhuǎn)返回錯(cuò)誤頁(yè)的問(wèn)題
