0

I am using Php Smarty on Linux.

I have a line in my Php file:

$phpsmart->display("pagetemplate.tpl");

This line is supposed to display pagetemplate.tpl. It doesn't.

Progrock
  • 7,373
  • 1
  • 19
  • 25
Sugumar Venkatesan
  • 4,019
  • 8
  • 46
  • 77
  • 1
    Have you checked your error log? – Progrock Dec 09 '15 at 11:48
  • Perhaps you aren't displaying errors? http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – Progrock Dec 09 '15 at 12:04
  • it shows this error Fatal error: Smarty error: unable to write to $compile_dir '/var/www/html/website/templates_c'. Be sure $compile_dir is writable by the web server user. in /var/www/html/website/includes/smarty/Smarty.class.php on line 1083 – Sugumar Venkatesan Dec 09 '15 at 12:51

2 Answers2

6

Enable errors, or check your logs. The most likely thing is that you haven't set up writeable directories needed by smarty.

I just installed smarty with composer:

$ composer.phar require smarty/smarty

And tried the demo:

( ! ) Fatal error: Uncaught --> Smarty: unable to write file ./templates_c/wrt56681191371d80_85949214 <-- thrown in /var/www/smarty/vendor/smarty/smarty/libs/sysplugins/smarty_internal_write_file.php on line 46

I then created that 'template_c' folder, and made it writeable by the web server.

( ! ) Fatal error: Uncaught --> Smarty: unable to write file ./cache/wrt566812bd6f7b08_17223124 <-- thrown in /var/www/smarty/vendor/smarty/smarty/libs/sysplugins/smarty_internal_write_file.php on line 46

I then created the 'cache' folder, and made it writeable by the web server.

The demo then worked.

See the quick install.

Progrock
  • 7,373
  • 1
  • 19
  • 25
-1

It doesn't display a tpl file even after changing the file permissions and ownership of a file.

for people who are having problem like this.

1) chmod -R 755 /var/www -> This will give read write permission to the owner and other for the group( the owner belongs to), and others the permission in read and execute. and this is assigned recursively so all your files and directories inside www will also be having the same permissions

2) chown -R apache:apache /var/www ->This will give make apache owner of www and including files. This is also applied recursively.

3)your website owner needs write permission to template_c file so check using ls -altr to see whether it has given the write permission, if write is like 755(rwxr-xr-x) and still not working change it to 777 (remember chmod). also check the cache folder..

4) If still it's not working may be selinux is protecting write access to your template_c file. so for this you need the following command

setsebool -P httpd_unified=1   -> This will disable selilnux for apache httpd. 

Enjoy!

Sugumar Venkatesan
  • 4,019
  • 8
  • 46
  • 77
  • `chown -R apache:apache /var/www` Please stop doing this, it gives the web server, and all the PHP code it's running, unfettered write access to everything! You only need to give write permissions to your smarty cache directory, which I hope is not publicly served by the web server. – Alex Barker Aug 23 '23 at 23:24