Smarty在linux下安装

Quick Install

This is a simple guide to get Smarty setup and running quickly. The online documentation includes a very thorough explanation of a Smarty installation. This guide is meant to be a quick and to-the-point way of getting Smarty working, and nothing more. The guide assumes you are familiar with the Linux system environment. Windows users will need to make file permission adjustments where necessary, or find a suitable hosting provider.

Install Library Files

Copy the Smarty library files to your system. In our example, we place them in/usr/local/lib/php/Smarty/. If you are using FTP/sFTP for server access, unzip the Smarty files locally and upload them to the proper directory.

command line

$> cd YOUR_DOWNLOAD_DIR
$> gtar -zxvf Smarty-3.0.tar.gz
$> mkdir /usr/local/lib/php/Smarty
$> cp -r Smarty-3.0/libs/* /usr/local/lib/php/Smarty

You should now have the following file structure:

file structure

/usr/local/lib/php/Smarty/
    debug.tpl
    plugins/
    Smarty.class.php
    sysplugins/

Setup Directories

You will need four directories setup for Smarty to work. These files are for templates, compiled templates, cached templates and config files. You may or may not use caching or config files, but it is a good idea to set them up anyways. It is also recommended to place them outside of the web server document root. The web server PHP user will need write access to the cache and compile directories as well.

In our example, the document root is /web/www.example.com/docs and the web server username is "nobody". We will keep our Smarty files under/web/www.example.com/smarty/. If you are using FTP/sFTP, your FTP software should help you with setting the file permissions. 775 means user/group = read/write, other = read.

command line

$> cd /web/www.example.com
$> mkdir smarty
$> mkdir smarty/templates
$> mkdir smarty/templates_c
$> mkdir smarty/cache
$> mkdir smarty/configs
$> chown nobody:nobody smarty/templates_c
$> chown nobody:nobody smarty/cache
$> chmod 775 smarty/templates_c
$> chmod 775 smarty/cache

Configure Scripts

Now we setup our application in the document root:

command line

$> cd /web/www.example.com/docs
$> mkdir myapp
$> cd myapp
$> vi index.php

Edit the index.php file to look like the following:

PHP

<?php

// put full path to Smarty.class.php
require('/usr/local/lib/php/Smarty/Smarty.class.php');
$smarty = new Smarty();

$smarty->setTemplateDir('/web/www.example.com/smarty/templates');
$smarty->setCompileDir('/web/www.example.com/smarty/templates_c');
$smarty->setCacheDir('/web/www.example.com/smarty/cache');
$smarty->setConfigDir('/web/www.example.com/smarty/configs');

$smarty->assign('name', 'Ned');
$smarty->display('index.tpl');

?>

Create Template

command line

$> nano /web/www.example.com/smarty/templates/index.tpl

Edit the index.tpl file with the following:

index.tpl

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

Now go to your new application through the web browser, http://www.example.com/myapp/index.php in our example. You should see the text "Hello Ned!" in your browser.

If you have any problems, you may want to run the Smarty Test Utility to be certain all files and folders are in place and have the correct permissions.

PHP

$smarty->testInstall();
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值