Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

One copy of Smarty for all websites in the server

 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Thu Jun 18, 2009 4:21 pm    Post subject: One copy of Smarty for all websites in the server Reply with quote

Did you ever think of one installation of Smarty to be used in all of your websites? This is possible if you have one dedicated/shared linux server. For those who do not have access to SSH (we will need this), you can ask your hosting provider help you with this article.

Concept and procedure:

Install a fresh version of Smarty somewhere in your Linux server. I hate Windows, and do not want to write any support tricks here.
For security reasons, it is better that these files are owned by root user, and shared in READ ONLY mode for other users.

Create a softlink to your public_html or htdocs folder to access the Smarty there! Hoorraayy. Thats all.

Examples:
Say, you put Smarty in: /var/general/smarty/lib on the server.
Your www.website1.com is located at /var/vhosts/website1.com/public_html
Then, do:
Code:
cd /var/vhosts/website1.com/public_html
ln -s /var/general/smarty/lib smarty

Now, use Smarty as you do it normally. Looks simple!
Smarty consumes around 385 kb of total size.
But to copy same file for each website, after learning from this tutorial may not be good Wink

Reuse as much as possible.
Back to top
View user's profile Send private message Visit poster's website
fornve
Smarty Rookie


Joined: 25 Apr 2008
Posts: 29
Location: Sheffield, UK

PostPosted: Sat Jul 04, 2009 7:49 am    Post subject: Reply with quote

1. Download and unpack smarty.

2. sudo mkdir /usr/share/php/smarty

3. sudo mv {unpacked_smarty}/libs/* /usr/share/php/smarty

4. Add /usr/share/php/smarty to php.ini include_path

5. Restart apache. Wink
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Sat Jul 04, 2009 4:54 pm    Post subject: Reply with quote

You don't even need a symlink, use the full path to the shared lib, or add the shared path to the php_include path like fornve mentioned.
Back to top
View user's profile Send private message Visit poster's website
philoertel
Smarty Rookie


Joined: 25 Jun 2009
Posts: 14
Location: Chicago, IL

PostPosted: Mon Jul 06, 2009 5:07 am    Post subject: Reply with quote

I do a lot of work for clients, developing on my home machine where I have full control but deploying to a strange environment. For me, that means staying away from php.ini :( I like the symlink route because subversion doesn't follow links but zip does. That way I avoid duplicating libraries in my repository and on my development box, but my deployed project has all its dependent libraries right there under one subtree. Feels like a dopey solution though. It doesn't handle heterogeneous development environments well (other developers in my shop use win and mac, so they won't use /usr/share/php), and it doesn't take advantage of existing libraries on client environments (more of a concern with bigger libraries like Zend Framework). It's cool to hear how you all deal with those same issues.
_________________
Phil Oertel
Application Developer
http://www.soliantconsulting.com
Back to top
View user's profile Send private message AIM Address
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Tue Jul 07, 2009 1:52 am    Post subject: Reply with quote

If I were deploying to strange environments, I would probably just bundle the Smarty libs with each deployment to keep things stable. There is a tradeoff no matter what you end up doing.
Back to top
View user's profile Send private message Visit poster's website
reffer101
Smarty n00b


Joined: 12 Nov 2009
Posts: 1

PostPosted: Tue Nov 17, 2009 2:06 pm    Post subject: Reply with quote

Hmmm Thanks now I can tell that to my Programmer, i tihink he already know how to do this but it was me who was unable to make him understand what i want.
BTW Thanks for the info...
_________________
Nike Watches | Adidas Watches
Back to top
View user's profile Send private message
Alexcsp
Smarty n00b


Joined: 17 Feb 2008
Posts: 3
Location: Scotland

PostPosted: Fri Apr 16, 2010 9:52 am    Post subject: One instance of Smarty on a server Reply with quote

Thanks for these tips.
can I also have seperate template folders for each website on the server?

how would you do you do that?
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Fri Apr 16, 2010 1:56 pm    Post subject: Re: One instance of Smarty on a server Reply with quote

Alexcsp wrote:
Thanks for these tips.
can I also have seperate template folders for each website on the server?

how would you do you do that?


See the extended setup in the install docs.

http://www.smarty.net/manual/en/installing.smarty.extended.php
Back to top
View user's profile Send private message Visit poster's website
Alexcsp
Smarty n00b


Joined: 17 Feb 2008
Posts: 3
Location: Scotland

PostPosted: Sun Apr 18, 2010 3:32 pm    Post subject: One Smarty, multiple sites Reply with quote

Thanks.

you know, I had already read that, but it did not sink in, that I could use one copy of the smarty class for multiple sites, using different template folders for each site.

Up till now, I've been copying the complete set of files to each site folder.

This will save me loads of disk space.

Thank you

Alex
Very Happy
Back to top
View user's profile Send private message Visit poster's website
kingyes
Smarty n00b


Joined: 13 Jan 2011
Posts: 3

PostPosted: Thu Jan 13, 2011 8:12 pm    Post subject: Reply with quote

from this docs: http://www.smarty.net/quick_install

Code:
<?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');

?>


I thinks this is the best way for that..
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP