Directories and Permissions

Now that we have the Smarty library files extracted and functioning we need to set up a few folders on the site's root directory (or the directory for which you are using Smarty). There are four directories that are required. They are as follows:

  1. cache - If enabled, Smarty stores cached versions of the pages here.
  2. configs - Stores the configuration files used by the templates.
  3. templates - This is where the templates are placed.
  4. templates_c - This is where Smarty compiles template pages.

These directory names can be changed if necessary but those are the defaults. See Figure 1 below for an example.

Fig 1. Sample Directory Structure

Smarty needs to be able to write to the cache and templates_c directories. The web server account is what will actually be writing files to these directories.

Windows users usually aren't affected by this, however in some cases the directories need to be setup to have write access to the 'anyone' group.

If you are on a *nix or mac machine you will need to use chmod (inside a Terminal window). Note that 770 provides tight security, but 775 can be used instead for convenience (allowing the developer to view these files freely).

Example chmod commands
// The webserver usually uses the nobody user
// This command has to be done by the superuser.  sudo might be necessary
chown nobody:nobody /www/example_site/cache/
chmod 770 /www/example_site/cache/

chown nobody:nobody /www/example_site/templates_c/
chmod 770 /www/example_site/templates_c/

Your Smarty setup is complete! That wasn't so bad now was it? It may seem like a lot at first but once you have done it a few times it's a breeze!

<- Previous Next ->