7

Smarty is complaining about permissions. I've written a small mvc framework for a project I'm working on and I need to be able to render templates in each controller. I went ahead and followed the Smarty installation instructions, and set all of the configuration options in my "front controller", or the page that routes requests to the rest of the application. The testinstall function says everything is kosher, yet when I attempt to render templates in my controllers, I end up with this.

Warning: mkdir(): Permission denied in /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php on line 28 Warning: rename(/tmp/wrt6piczo,./templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php): No such file or directory in /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php on line 48 Warning: chmod(): No such file or directory in /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php on line 50 Warning: include(./templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php): failed to open stream: No such file or directory in /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_template.php on line 423 Warning: include(): Failed opening './templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_template.php on line 423

I have tested the rest of my framework independently and everything seems to work. My "front controller" routes requests properly to the correct controllers, and I seem to be able to render regular HTML just fine.

Additionally, I have chmodded all of the Smarty library folders as well as the other required directories to 777 just for the sake of testing. I'm still receiving the same permissions errors.

EDIT

These are the settings I've used for all the required smarty folders.

$smarty->setTemplateDir('lib/smarty/templates');
$smarty->setCompileDir('lib/smarty/templates_c');
$smarty->setCacheDir('lib/smarty/cache');
$smarty->setConfigDir('lib/smarty/configs');
afkbowflexin
  • 4,029
  • 2
  • 37
  • 61
  • 2
    Why do you want to use Smarty? Why not just use PHP itself (and save yourself from these hassles)? – ircmaxell Jan 03 '11 at 21:43
  • 3
    The end result must be designer friendly. I will not likely be designing all of the views myself. – afkbowflexin Jan 03 '11 at 21:56
  • What have you set the smarty compile_dir to? Does the web server have permissions to write there? – James Jan 03 '11 at 22:21
  • @Josh If a designer can understand the concept of a variable, is not less unfriendly than {$var}. If they can understand the concept of control structures, 2):?> ... is not less unfriendly than {if 1>2}...{/if}. By using Smarty you are making huge sacrifices in terms of performance and overall maintainability. – mfonda Jan 03 '11 at 22:25
  • compile_dir is set to 'lib/smarty/templates_c'. The server does indeed have permissions there. Additionally, the designers that will need to use this are familiar with template languages. It's not really up to me. As far as performance and maintainability are concerned, the app is a small internal application (less than 30 users.) – afkbowflexin Jan 03 '11 at 22:35
  • 2
    Personally, I kind of like Smarty. Anyway, can you show us the Smarty Config settings you are using? If the directories have the right permissions, then maybe it is just looking in the wrong places... – Luke Stevenson Jan 03 '11 at 23:45
  • 1
    I switched to Dwoo. Problem fixed. – afkbowflexin Jan 04 '11 at 21:41

6 Answers6

7

Proper permissions solved it for me:

chown -R www-data /var/www/HRTRL
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
4

Could it be a problem with relative paths? Could you add the complete paths for you set****Dir functions, so you'll be sure you're using the correct locations.

If you call this from a /specialdir/thisdirhasonlyaPHPfile/file.php location, you might get in trouble.

Nanne
  • 64,065
  • 16
  • 119
  • 163
0

For anyone else dealing with permission issues with Smarty after following all of the above (Checking config/chown/chmod etc...) We came across an issue whilst running Smarty on SE(Security Enhanced)Linux.

The compile/cache directories were sub-directories inside of a ~/tmp directory.

The default targeting policy prevents writes to tmp directories.

You can use semanage to update contexts/policies. You'll most likely need to create a new policy to assign the httpd_sys_rw_content_t context to the directory your web-app needs to write too.

More information: http://www.serverlab.ca/tutorials/linux/web-servers-linux/configuring-selinux-policies-for-apache-web-servers/ t

supert3d
  • 55
  • 7
-2

According to the documentation, permission of 'template_c' folder should be 775. But it does not work sometime. You have to set its permission to 777.

Mrid
  • 397
  • 2
  • 9
  • I would look into why 775 doesn't work as that should be the loosest permissions for any file/folder in your project and is why the documentation says 775 and not 777. – None Mar 13 '17 at 20:57
-2

Simply comment the following line from the index.php file.

$smarty->caching = true;

This will solve your problem.

-2

You should check again access permission for write. I had the same errors, so I have set permissions to 777 for 'templates_c' folder and anything inside of it and now it works. However I had to repeat this operation for 3 times in Filezilla, don't know why it didn't change the permissions at once.

denu
  • 2,170
  • 2
  • 23
  • 28