Smarty PHP Template Engine - file permission errors and missing templates - php

I am having a lot of headaches with the Smarty PHP Template Engine - Version 2.6.0 (smarty.net)
An error I keep getting in my error_log is
PHP Fatal error: Smarty error: unable to write to $compile_dir
'/var/www/vhosts/domain/library/templates/compiled'. Be sure
$compile_dir is writable by the web server user. in
/var/www/vhosts/domain/library/Smarty-2.6.0/libs/Smarty.class.php on
line 1088
I have made the folder and files writable with permissions set to 777 but still this error keeps happening.
It is making updating the template files a nightmare as currently I am updating the code in two places -> the templates folder and the compiled folder. It's like no compilation is happening so editing the already compiled file is the only way I can make a change to the site.
However, I had a template file that was being included in another template file and this was not in the compiled directory. After making a simple text change in this file has now completely removed that section of the site and the page just breaks that section is supposed to appear.
I am completely stumped with this and am hoping some of you with Smarty experience will be able to help me out.
Thank you in advance.

make sure you assign the compile dir in the smarty configuration file
here is sample of the config i use and it's working fine with me
/////Smarty including
require_once('libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = 'template'; // template folder
$smarty->compile_dir = 'cache'; // Create a Folder Cache with 777 Permission
This Settings works fine with latest smarty edition Smarty 3.x.

You need to edit the file httpd.conf
vim +231 /etc/httpd/conf/httpd.conf
See what User and and Group are specified there,
if for example you see this:
User asterisk
Group asterisk
Then you need to give permission to that user/group on the directory /var/www/
chown -R asterisk:asterisk /var/www/

Related

Joomla 3.x Administrator Error : 0 Cannot write to log

I wrote a joomla 3.x simple web site on my local machine and it worked fine. I deployed this to 1&1.com and the front end works fine but the control panel throws an error each time I try to log in saying "0: cannot write to log".
I have tried relative and absolute paths to the log folder in the $log_path parameter of the configuration.php and changed the permissions to the folder and files to all sorts of combinations and still I get the same error? I have created a new log folder and pointed the to that and still no joy?
has anyone come across this error using 1&1.com? I see some suggestions that 1&1.com are really bad with joomla support and I may be best trying another host? I am in 30 day money back guarantee so that is going to be my next move.
Cheers
Alex
First check this link https://joomla.stackexchange.com/questions/4673/error-0-cannot-open-file-for-writing-log-while-updating and if everything is fine and still this doesnt help then proceed to next step
Step:1 get the base path by writing this code to a file and uploading it through ftp
<?php
$basepath = getcwd();
echo "Your base Path is: ";
echo $basepath;
?>
When you run that file suppose it is named base.php then go to http://yoursite.com/base.php and get your base path.
Step:2 Create a new log and tmp folder
Now as You have got the base path, create a folder in your main joomla installation and name it newlog with permission 755.
Step:3 Change path in GLobal Configuration
In your global configuration give the base path appending the new folder path. Suppose you get basepath as /var/www/joomla then uou give the log path as
/var/www/joomla/newlog
I imagine you might have asked 1&1 already, it may be something they know very well.
Anyway make sure you have the correct configuration paths (absolute!) in the configuration.php and that the folder and its files are writable by the user who runs the website instance.
Also clear /cache and /administrator/cache for good measure, as they may have cached some non-authenticated results.

Smarty librairies unaccesible by php

I am installing Smarty on Ubuntu. I follow the installation notice:
placing libraries under usr/local/lib/php/Smarty;
creating smarty directories under var/ (as far as I understand, that must not be placed under the web server document root directory);
creating my project under the root directory var/www/ with a php file for executing the application.
I does not work so far, because, as I suppose, any php file outside the server root directory var/www/ is not readable by php.
How can I manage to both place those libraries .php files outside the root server directory and having them read by php?
Where did I make a mistake?
Thank you for your help.
Victor

drupal file_check_path return false

I am working on files in drupal. i use local wamp server with drupal6.
my drupal path is localhost/drupal6 .i have a file in this path <drupal root >\files\images\111.jpg .
$image='/drupal6/files/images/111.jpg';
I want copy(or move) this file to another sub folder in this path but give me error in php copy($image,'anotherdestination') or drupal_copy($image,'anotherdestination',FILE_EXISTS_RENAME).
when i use var_dump(file_check_path($image)); it return me false .
the files and iamges folder have all permission for any user in windows.
where is the problem?
notice: i wrote all of this code in a function in a custom module with path sites/all/module/mymodule/mymodule.module
There's a difference between how files are accessed over HTTP and via the file system. Over web /drupal6/files/images/111.jpg is perfectly fine, since it'll be evaluated as http://example.com/drupal6/files/images/111.jpg. But I bet you do not have a drupal6 directory in the root of your file system.
You probably want something like this.
copy('c:\drupal6\files\images\111.jpg', 'c:\drupal6\files\other_images\111.jpg');
I'm not entirely sure about paths in Windows but I think that should be correct.

Smarty permissions problems

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');
Proper permissions solved it for me:
chown -R www-data /var/www/HRTRL
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.
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
Simply comment the following line from the index.php file.
$smarty->caching = true;
This will solve your problem.
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.
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.

Yii PHP Framework- Implementation

I was just curious if Yii is supposed to be compiled into PHP or not. Is it possible to use Yii just by copying the Framework to a folder on the server and then including something (something as in one of the yii files- I am not sure how it works) in the scripts I wish to use the framework for?
(Noob when it comes to frameworks and usage)
Thanks,
Josh
I'll go with the line
Is it possible to use Yii just by
copying the Framework to a folder on
the server and then including
something
and answer yes :p Though, you should just follow webapp creation through yiic webapp like
so:
Download the yii (yii-someversion.tar.gz or what have you) distribution,
extract it somewhere (e.g. /opt/yii in *nix or C:/web/yii in windows.)
Now put that directory in your path ($PATH in *nix, or %PATH% in windows),
go to a shell / command prompt, change the directory to your
webserver's document root and do a yiic webapp <app folder name>
After answering a couple config question, you should have an look at the
index.php created there, you should have something like:
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/../yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
require_once($yii);
Yii::createWebApplication($config)->run();
and that's about it :p
Yii is a PHP framework and not an extension. You can just copy-paste it somewhere. Be sure to put the destination folder into your include path.
you just need to do it once to get an instance, and then you can copy this instance as much as you want, provided that the path of yii.php file in the index.php file is right, for me I usually copy the framework folder from the yii folder, paste it inside the instance in the folder "protected" and then change the path in index.php to "/protected/framework/yii.php"

Categories