CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • Smarty won't create directories in templates_c, with solution
Pages: [1]

Author Topic: Smarty won't create directories in templates_c, with solution  (Read 4504 times)

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Smarty won't create directories in templates_c, with solution
November 18, 2010, 09:35:49 am
We ran into a problem where Smarty wouldn't seem to create new directories or compiled templates in templates_c.

So for instance, just deleting all the contents of templates_c (a recommended solution to some problems) would result in most of CiviCRM just not rendering correctly and absolutely nothing new being created within templates_c.

If we kept templates_c as it was, most pages would render OK but a few would render improperly, with the main part of the page not showing up at all.

It turned out that those were the pages that didn't have a subdirectory already created under templates_c to hold their compiled template file.  So when Smarty would try to create a new template and then create a new subdirectory of templates_c to store it in, the process would fail (silently, unfortunately) and we were left wondering why those pages just didn't work.

I first thought of permissions problems but after chmodding everything under templates_c to 777 there was still no effect.

It turns out the problem was the Smarty uses open_basedir to determine whether or not it can create a specific directory (see core.create_dir_structure.php under the Smarty subdirectory).

In our hosting environment, for whatever reason, open_basedir didn't include the main html directories (even though php can indeed create directories there, no problem).  So even though Smarty could create directories there, it was using open_basedir to erroneously figure out that it *couldn't*, and then not even trying.

Solution was to add a value to define open_basedir in the main .htaccess file:

Code: [Select]
php_value open_basedir /nfs:/tmp:/usr/local:/etc/apache2/gs-bin:/home/00000/domains/ourdomain.com/html/:/home/00000/data/tmp/
The first part (/nfs:/tmp:/usr/local:/etc/apache2/gs-bin) is the open_basedir as defined by default on this host.  The rest is the part we added to allow Smarty to create directories.  The 00000 and ourdomain.com parts are specific to our account.  (This could be narrowed down to improve security, I presume.)

I think open_basedir can also be defined in php.ini rather than .htaccess, though I haven't tried that.

You can check what open_basedir to on your system with a bit of code like this:
Code: [Select]
<?php
        
echo ini_get('open_basedir');
?>

If you're using open_basedir (ie, it's non-empty), your templates_c directory must be a subdirectory of one of the paths given in open_basedir.  More info about open_basedir here and info from the Smarty forums here.

This is in CiviCRM CiviCRM 3.2.0, which uses Smarty ver 2.6.26, all under Drupal 6.19.
« Last Edit: November 18, 2010, 11:21:17 am by flug »

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Smarty won't create directories in templates_c, with solution
November 18, 2010, 10:59:10 am
Interesting.  From the way I am reading this, it sounds like you might want to report this to smarty as well?
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Re: Smarty won't create directories in templates_c, with solution
November 18, 2010, 11:08:13 am
Quote from: michaelmcandrew on November 18, 2010, 10:59:10 am
Interesting.  From the way I am reading this, it sounds like you might want to report this to smarty as well?

Yes, it's definitely a flaw in Smarty.  I don't know how you'd really want to do this in the ideal world, but definitely not this way.  However, the approach would work if php's open_basedir setting worked as advertised (ie, that php can open/change any file unless it's listed in open_basedir).  So it may be somewhat unusual that in our hosting setup, open_basedir is used but doesn't include some paths that php can, indeed, access.

Also when it happens, there is no error reporting--it just silently fails.  Makes it a bit tough to track down.

FWIW, Smarty says this: Note, if you are using open_basedir then template_c (and/or cache) must exist in a path reachable with that setting.
« Last Edit: November 18, 2010, 11:14:31 am by flug »

ngingras

  • I’m new here
  • *
  • Posts: 15
  • Karma: 0
Re: Smarty won't create directories in templates_c, with solution
January 01, 2011, 11:06:40 pm
flug: THANKS!  ;D

This was exactly what has been driving me mental for the past two hours.

Ran into this issue on a client's web host (Media Temple) and your solution worked perfectly. Now just have to make a bunch of notes so that if the client moves the site again, they remember to remove that line from .htaccess.


flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Re: Smarty won't create directories in templates_c, with solution
January 04, 2011, 12:01:47 am
Yes, we're on mediatemple as well, so it might be some quirk of their gridserver thingamajig.

(mt) matt

  • I’m new here
  • *
  • Posts: 1
  • Karma: 0
Re: Smarty won't create directories in templates_c, with solution
January 04, 2011, 04:16:14 pm
Just read over things, and was happy to see that you were successful. We always are looking on improving the (gs) as well as our knowledge base wiki articles. Seeing as how we many have a number of customers using Smarty, we'd love to have you write up a wiki article on how you came across the fix. Also, if you ever have issues or questions,  feel free to contact us through the phones, forums, or Twitter for help. Let me know if we can help.

voicebox

  • I’m new here
  • *
  • Posts: 9
  • Karma: 0
  • CiviCRM version: 4.0
  • CMS version: 7.0
  • MySQL version: 5.1.26
  • PHP version: 5.2.14
Re: Smarty won't create directories in templates_c, with solution
April 26, 2011, 08:57:30 am
Where in the htaccess file did you add this line?

Thanks,
Josh

carnellm

  • I’m new here
  • *
  • Posts: 6
  • Karma: 1
    • Palmetto Technology Hub
  • CiviCRM version: 3.4.2, 4.1.alpha2
  • CMS version: Drupal 6.2, 7.0 and WordPress 3.3
  • PHP version: 5.2.16
Re: Smarty won't create directories in templates_c, with solution
June 14, 2011, 05:28:23 pm
 Just wanted to say thanks! This cured my MediaTemple / CiviCRM issue.  ;D

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • Smarty won't create directories in templates_c, with solution

This forum was archived on 2017-11-26.